Help with VBA If ElseIf

danboi10

Registered User.
Local time
Today, 15:14
Joined
Aug 15, 2012
Messages
19
Hi,

I have created a macro which takes the data in an access data base and produces a letter based on the information. I am almost at the end but have found a variable that I don't seem to be able to find an answer for. The issue in questions relates to a field called first name. It's not always the case that we would know the full first name and on occasions we just enter the initial of the first name. This means that the letter becomes "Dear R". I have tried several different If else statement in the hope that if first name = 1 then "dear sir", else if first name = 2 then the full name appears (sorry if this is a bit vague)! I seem to be getting nowhere fast:banghead:!

Code:
f [First Name] = 1 Then
WrdApp.Selection.TypeText Text:="Sir/Madam"
ElseIf [First Name] = 2 Then
WrdApp.Selection.TypeText Text:=StrConv([First Name], vbProperCase)
End If

Thanks for any help.

Dan.
 
Why do you have the If statement condition is =1 or =2 what does it actually mean??
 
What Im trying to do is say If the field "first Name" is only 1 letter then type "dear sirs". Else if the field "first name" is greater than 1 then enter the data from the "first name" field.

eg somebody puts R in the "first name" field and the letter would be "dear sir" but if somebody wrote Richard in the field then the name Richard would appear on the letter.
 
Okay,, then change this as the If condition..
Code:
If Len([FirstName] & "") = 1 Then
    WrdApp.Selection.TypeText Text:="Sir/Madam"
Else
     WrdApp.Selection.TypeText Text:=StrConv([First Name], vbProperCase)
End If
There would be no need for another If..
 
That's brilliant. Done the trick nicely. Thanks very much
 

Users who are viewing this thread

Back
Top Bottom