I Need VBA Help!!!!

Discussion in 'Software' started by IdahoGeek, Nov 8, 2004.

  1. IdahoGeek

    IdahoGeek Private E-2

    Hello Folks I need some VBA Help.
    :rolleyes:
    I'm attempting to write a function using If..Then..ElseIf statements.
    Not all my code works. Can somebody tell me what I'm missing. Here is the code.
    Public Function asaFullName(strFirst As String, strSpouse As String, _
    strLast As String) As String

    Dim strTempName As String

    If (strSpouse) = "A" Then
    strTempName = (strFirst & " " & strLast)

    ElseIf (strSpouse) = "B" Then
    strTempName = (strFirst & " " & "and" & " " & strSpouse & " " & strLast)

    asaFullName = strTempName
    End If
    End Function

    Thanks in Advance.
     
  2. Wookie

    Wookie Sergeant Major

    It has to be something in the bigger picture, I see nothing wrong with that and thrw it in a project and it worked just fine. Can you post the whole program? Or at least give me an idea of the problem your having?
     
  3. QuickSilver

    QuickSilver Corporal

    Hmmm... You haven't said that the code didn't run - just that it didn't work properly....
    I noticed the following :

    Code:
    If (strSpouse) = "A" Then
    strTempName = (strFirst & " " & strLast)
    
    ElseIf (strSpouse) = "B" Then
    strTempName = (strFirst & " " & "and" & " " & strSpouse & " " & strLast)
    
    asaFullName = strTempName
    End If 
    the following line :
    Code:
    asaFullName = strTempName
    is only going to be executed in the ElseIf branch of code. If you put the
    End If line of code before 'asaFullName = ...' then it will be executed no matter which way the IF Statement branches, and the string assignment will happen as I suspect you want it to...

    Is that right? Let me know...
     
  4. IdahoGeek

    IdahoGeek Private E-2

    QuickSilver you are the winner. I did what you seuggested and it runs fine now. Thanls for the explanation as well. I now understand why it failed. I was so busy looking at the logic of the function that I simply did not check the syntax. Thanks. Where do I send the check?? (Kidding of course)
     
  5. QuickSilver

    QuickSilver Corporal

    Glad I could help :)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds