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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Help 1

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
I am using the following code to autopopulate a word document. Everything works fine except there are times when not all of the fields are populated so i get an error "Invalid use of NULL". Can someone please show me how I can adjust the following code so that if a field is NULL or empty it will just skip it and go to the next one? Below is a sample of the code im using

Code:
        .ActiveDocument.Bookmarks("bfirst").Select
        .Selection.Text = (CStr(Forms!frm_quote!bfirst))
        .ActiveDocument.Bookmarks("blast").Select
        .Selection.Text = (CStr(Forms!frm_quote!blast))
        .ActiveDocument.Bookmarks("bcompany").Select
        .Selection.Text = (CStr(Forms!frm_quote!bcompany))
        .ActiveDocument.Bookmarks("baddress1").Select
        .Selection.Text = (CStr(Forms!frm_quote!baddress1))

Thank you in advance for any help!

Paul
 
I'd have a look at the Nz() function.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
This should be one way (I'll just use one block of your code as an example).

Change:

.ActiveDocument.Bookmarks("bfirst").Select
.Selection.Text = (CStr(Forms!frm_quote!bfirst))

to

if not isnull(Forms!frm_quote!bfirst) then
.ActiveDocument.Bookmarks("bfirst").Select
.Selection.Text = (CStr(Forms!frm_quote!bfirst))
end if

 
Thank you tigersbh !!! that worked perfectly!!!
 
Using HarleyQuinn's suggestion would have saved you adding extra lines of codes. But I guess if its too much trouble looking up the Nz() function in Help or Google...


 
Furthermore, why Select ?
.ActiveDocument.Bookmarks("bfirst").Text = Trim(Forms!frm_quote!bfirst & "")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top