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

handling null value in Access-Word merge

Status
Not open for further replies.

leeroi

Technical User
Jun 5, 2000
122
US
I apologize ahead of time if this question has already been addressed- I couldn't find anything relevant after doing a site search.

I am merging data from Access into a Word document. Opening a form calls code in the specified Module, and merges data from the form into bookmarked locations in the specified Word document.

The merge will not run properly is any of the fields are empty. What do I need to put in the code module to address this and allow a null value? It is only one database field that is causing the problem, so the solution can be focused on that field, rather than needing to address the possibility of a null value in any one of the merging fields.

I am not a coding wizard, so a simple explanation would be greatly appreciated. Thank you.

Lee
 
What do I need to put in the code module to address this and allow a null value
Which code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Could you be more specific? Here's what I have in the module. Perhaps it would help if I include some sample code.As I noted earlier, it's only the PhysicianID bookmark that's giving me a problem.

Public Function CreateMerge_ROFCoverLetter(strDocPath As String)

If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If

Dim dbs As Database
Dim objWord As Object
Set dbs = CurrentDb

Set objWord = CreateObject("Word.Application")

With objWord
.Visible = True
.Documents.Open (strDocPath)

.activedocument.Bookmarks("PhysicianID").Select
.Selection.Text = CStr(Nz(Forms![frmMergeROFCoverLetter]![PhysicianName]))
 
Why don't you set the default value of the field in the Access table to "0"? That way when the data is transferred from Access to Word there is a value for it to process.

Travis
 
Replace this:
.Selection.Text = CStr(Nz(Forms![frmMergeROFCoverLetter]![PhysicianName]))
With something like this:
If Trim(Forms!frmMergeROFCoverLetter!PhysicianName & "") = "" Then
.Selection.Text = "Unknown"
Else
.Selection.Text = Forms!frmMergeROFCoverLetter!PhysicianName & ""
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you. The coding you suggested worked beautifully.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top