Can't find field on subform - bookmarks

K

Kenny G

I get the message DatabaseName Can't find the field 'DirectorCoordinator'
entered in your expression. Run Time Error 2465

I am using bookmarks to obtain data from a table for this letter.

Below is my code and if you can take a look at it and please tell me what is
incorrect.

Thanks,


Sub PrintTracerSurveyReport(sfrmReports)
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objBookmarks As Bookmark

'Launch Word and load the JCAHOTracerPreSurveyReport template
Set objWord = New Word.Application
objWord.Visible = True
Set objDoc = objWord.Documents.Add("S:\Quality & Process
Improvement\QPI\JCAHO PreSurvey Tool\Documents\JCAHOPreSurveyReport3.dot")
'Add information using predefined bookmarks

With objDoc.Bookmarks
.Item("DirectorCoordinator").Range.Text =
[sfrmReports].Form!DirectorCoordinator
.Item("SurveyID").Range.Text = [sfrmReports].Form!SurveyID
.Item("SurveyDate").Range.Text = [sfrmReports].Form!SurveyDate
.Item("SubSiteName").Range.Text = [sfrmReports].Form!SubSiteName
.Item("Standard").Range.Text = [sfrmReports].Form!Standard
.Item("Observation").Range.Text = [sfrmReports].Form!Observation
.Item("Recommendation").Range.Text =
[sfrmReports].Form!Recommendation
.Item("FollowupComments").Range.Text =
[sfrmReports].Form!FollowupComments
End With

objWord.PrintOut
objDoc.Close wdDoNotSaveChanges
objWord.Quit

End Sub
 
G

Graham Mandeno

Hi Kenny

How are you declaring and calling this procedure?

It looks like it is specific to a particular form and therefore should be in
that form's class module. In which case, assuming sfrmReports is a subform
control on the form owning the code, the subform is in the current scope and
does not need to be passed as an argument.

If the code is shared and is in a standard module, then you should declare
the type of the argument:

Sub PrintTracerSurveyReport(sfrmReports As Subform)

If you are still having trouble, temporarily change the first bookmark
assignment to a literal:

Item("DirectorCoordinator").Range.Text = "XXXXX"

and see if the code still breaks on that line, or if it then chokes on
SurveyID.
 
K

Kenny G

Graham,

It was in a standard module. I appreciate your help.

Regards,
--
Kenny G


Graham Mandeno said:
Hi Kenny

How are you declaring and calling this procedure?

It looks like it is specific to a particular form and therefore should be in
that form's class module. In which case, assuming sfrmReports is a subform
control on the form owning the code, the subform is in the current scope and
does not need to be passed as an argument.

If the code is shared and is in a standard module, then you should declare
the type of the argument:

Sub PrintTracerSurveyReport(sfrmReports As Subform)

If you are still having trouble, temporarily change the first bookmark
assignment to a literal:

Item("DirectorCoordinator").Range.Text = "XXXXX"

and see if the code still breaks on that line, or if it then chokes on
SurveyID.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Kenny G said:
I get the message DatabaseName Can't find the field 'DirectorCoordinator'
entered in your expression. Run Time Error 2465

I am using bookmarks to obtain data from a table for this letter.

Below is my code and if you can take a look at it and please tell me what
is
incorrect.

Thanks,


Sub PrintTracerSurveyReport(sfrmReports)
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objBookmarks As Bookmark

'Launch Word and load the JCAHOTracerPreSurveyReport template
Set objWord = New Word.Application
objWord.Visible = True
Set objDoc = objWord.Documents.Add("S:\Quality & Process
Improvement\QPI\JCAHO PreSurvey Tool\Documents\JCAHOPreSurveyReport3.dot")
'Add information using predefined bookmarks

With objDoc.Bookmarks
.Item("DirectorCoordinator").Range.Text =
[sfrmReports].Form!DirectorCoordinator
.Item("SurveyID").Range.Text = [sfrmReports].Form!SurveyID
.Item("SurveyDate").Range.Text = [sfrmReports].Form!SurveyDate
.Item("SubSiteName").Range.Text =
[sfrmReports].Form!SubSiteName
.Item("Standard").Range.Text = [sfrmReports].Form!Standard
.Item("Observation").Range.Text =
[sfrmReports].Form!Observation
.Item("Recommendation").Range.Text =
[sfrmReports].Form!Recommendation
.Item("FollowupComments").Range.Text =
[sfrmReports].Form!FollowupComments
End With

objWord.PrintOut
objDoc.Close wdDoNotSaveChanges
objWord.Quit

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top