Hi there,
I've got this expression that's giving me grief. I'm not the best programmer, however, this expression is returning the correct TutorID.
What I'm doing is taking the result and passing it into a word document. I'll past in the rest of the code below. My code is taking the records from one form and sending them into a word document which has bookmarks setup. There are a couple of records that come from a different table that also need to be passed in. That's why I'm doing a dlookup. If you have a different idea, I'm open to it.
Thanks in advance for your help.
Marshall
.Selection.Text = DLookup([FirstName], [Add or Delete Employees], "TutorID = " & (Forms![Add or Delete a Customer]![TutorID]))
-------------------------------------------
Public Function CreateWordLetter(strDocPath As String)
'function returns nothing, but I created this as a
'function so all those macro users out there could
'use it also.
'if no path is passed to function, exit - no further
'need to do anything
If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If
Dim dbs As Database
Dim objWord As Object
Dim PrintResponse
Set dbs = CurrentDb
'create reference to Word Object
Set objWord = CreateObject("Word.Application")
'Word Object is created - now let's fill it with data.
With objWord
.Visible = True
.Documents.Open (strDocPath)
'move to each bookmark, and insert correct text.
.ActiveDocument.Bookmarks("ParentsTitle").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]!ParentsTitle))
.ActiveDocument.Bookmarks("FirstName").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Parents FirstName]))
.ActiveDocument.Bookmarks("LastName").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Parents LastName]))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Address]))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![City]))
.ActiveDocument.Bookmarks("Province").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Province]))
.ActiveDocument.Bookmarks("PostalCode").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Postal Code]))
.ActiveDocument.Bookmarks("TutorFirstName").Select
.Selection.Text = DLookup([FirstName], [Add or Delete Employees], "TutorID = " & (Forms![Add or Delete a Customer]![TutorID]))
'.ActiveDocument.Bookmarks("TutorLastName").Select
'.Selection.Text = (CStr(Forms![Add or Delete Employees]![LastName]))
'.ActiveDocument.Bookmarks.Add Name:=ParentsTitle
'Range = Selection.Range
'** continue the ActiveDocument and Selection statements for each bookmark that you have on the Word Document **
End With
'find out if the user would like to print the document
'at this time.
PrintResponse = MsgBox("Print this document?", vbYesNo)
If PrintResponse = vbYes Then
objWord.ActiveDocument.PrintOut Background:=False
End If
'release all objects
Set objWord = Nothing
Set dbs = Nothing
End Function
---------------------------------------------
I've got this expression that's giving me grief. I'm not the best programmer, however, this expression is returning the correct TutorID.
What I'm doing is taking the result and passing it into a word document. I'll past in the rest of the code below. My code is taking the records from one form and sending them into a word document which has bookmarks setup. There are a couple of records that come from a different table that also need to be passed in. That's why I'm doing a dlookup. If you have a different idea, I'm open to it.
Thanks in advance for your help.
Marshall
.Selection.Text = DLookup([FirstName], [Add or Delete Employees], "TutorID = " & (Forms![Add or Delete a Customer]![TutorID]))
-------------------------------------------
Public Function CreateWordLetter(strDocPath As String)
'function returns nothing, but I created this as a
'function so all those macro users out there could
'use it also.

'if no path is passed to function, exit - no further
'need to do anything
If IsNull(strDocPath) Or strDocPath = "" Then
Exit Function
End If
Dim dbs As Database
Dim objWord As Object
Dim PrintResponse
Set dbs = CurrentDb
'create reference to Word Object
Set objWord = CreateObject("Word.Application")
'Word Object is created - now let's fill it with data.
With objWord
.Visible = True
.Documents.Open (strDocPath)
'move to each bookmark, and insert correct text.
.ActiveDocument.Bookmarks("ParentsTitle").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]!ParentsTitle))
.ActiveDocument.Bookmarks("FirstName").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Parents FirstName]))
.ActiveDocument.Bookmarks("LastName").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Parents LastName]))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Address]))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![City]))
.ActiveDocument.Bookmarks("Province").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Province]))
.ActiveDocument.Bookmarks("PostalCode").Select
.Selection.Text = (CStr(Forms![Add or Delete a Customer]![Postal Code]))
.ActiveDocument.Bookmarks("TutorFirstName").Select
.Selection.Text = DLookup([FirstName], [Add or Delete Employees], "TutorID = " & (Forms![Add or Delete a Customer]![TutorID]))
'.ActiveDocument.Bookmarks("TutorLastName").Select
'.Selection.Text = (CStr(Forms![Add or Delete Employees]![LastName]))
'.ActiveDocument.Bookmarks.Add Name:=ParentsTitle
'Range = Selection.Range
'** continue the ActiveDocument and Selection statements for each bookmark that you have on the Word Document **
End With
'find out if the user would like to print the document
'at this time.
PrintResponse = MsgBox("Print this document?", vbYesNo)
If PrintResponse = vbYes Then
objWord.ActiveDocument.PrintOut Background:=False
End If
'release all objects
Set objWord = Nothing
Set dbs = Nothing
End Function
---------------------------------------------