Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Access to Word IF statement 2

Status
Not open for further replies.

sharonniles

Programmer
May 31, 2001
38
US
Good Afternoon,
I'm filling in a Word document using Access XP. To fill in each line I'm using for example:
objWord.Selection.TypeText Text:=Me![First Name] & " " & Me![Last Name]

Let's say the first name field is null, how can I put an IF statement to change the first name field to "Mr.".

I tried:
if objWord.Selection.TypeText Text:=Me![First Name] is null then
objWord.Selection.TypeText Text:="Mr." & Me![Last Name]
else
objWord.Selection.TypeText Text:=Me![First Name] & " " & Me![Last Name]
end if

Obviously this is wrong. What is the correct syntax?

Thanks

 



hi,
Code:
if Me![First Name] = "" then
   objWord.Selection.TypeText Text:="Mr." & Me![Last Name]
else
   objWord.Selection.TypeText Text:=Me![First Name] & " " & Me![Last Name]
end if

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Either:
objWord.Selection.TypeText Text:=Nz(Me![First Name], "Mr.") & " " & Me![Last Name]
Or:
objWord.Selection.TypeText Text:=IIf(Trim(Me![First Name] & "") = "", "Mr.", Me![First Name]) & " " & Me![Last Name]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you Skip and PHV both solutions were exactly what I was looking for.

Sharon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top