Object Variable or With Block Not Set

K

Kenny G

Hi,

I'm getting the above error message when I use the following code. I am new
to Access/Word Automation. Would someone tell me what I did wrong?

Sub PrintConsentLetterWithWord(frmConsent)
Dim objWord As Word.Application
Dim objDoc As Word.Document

'Launch Word and load the ConsentLetter template
Set objWord = New Word.Application
objWord.Visible = False
Set objDoc = objWord.Documents.Add("S:\Quality & Process
Improvement\QPI\ RWJ Consent DB\RWJProviderLetter.dot")
'Add information using predefined bookmarks


With objDoc.Bookmarks
.Item("MedicalRecordsNumber").Range.Text = frmConsent.MRN
.Item("FirstName").Range.Text = frmConsent.FName
.Item("LastName").Range.Text = frmConsent.LName
.Item("Provider").Range.Text = frmConsent.Provider
.Item("Employee").Range.Text = frmConsent.Employee

End With

objWord.PrintOut
objDoc.Close wdDoNotSaveChanges
objWord.Quit



End Sub

Thank You,
 
P

Perry

Replace
Sub PrintConsentLetterWithWord(frmConsent)
by
Sub PrintConsentLetterWithWord(frm As frmConsent)

and replace all [frmConsent] calls in the subroutine
.Item("MedicalRecordsNumber").Range.Text = frmConsent.MRN
by the new object variable [frm], like in
..Item("MedicalRecordsNumber").Range.Text = frm.MRN

Krgrds,
Perry
 
K

Kenny G

Perry,

Many thanks - that worked great. Also on the line to the drive where the
document is kept I found a space that should not have been there. It's the
little things.

Cheers,
--
Kenny G


Perry said:
Replace
Sub PrintConsentLetterWithWord(frmConsent)
by
Sub PrintConsentLetterWithWord(frm As frmConsent)

and replace all [frmConsent] calls in the subroutine
.Item("MedicalRecordsNumber").Range.Text = frmConsent.MRN
by the new object variable [frm], like in
..Item("MedicalRecordsNumber").Range.Text = frm.MRN

Krgrds,
Perry

Kenny G said:
Hi,

I'm getting the above error message when I use the following code. I am
new
to Access/Word Automation. Would someone tell me what I did wrong?

Sub PrintConsentLetterWithWord(frmConsent)
Dim objWord As Word.Application
Dim objDoc As Word.Document

'Launch Word and load the ConsentLetter template
Set objWord = New Word.Application
objWord.Visible = False
Set objDoc = objWord.Documents.Add("S:\Quality & Process
Improvement\QPI\ RWJ Consent DB\RWJProviderLetter.dot")
'Add information using predefined bookmarks


With objDoc.Bookmarks
.Item("MedicalRecordsNumber").Range.Text = frmConsent.MRN
.Item("FirstName").Range.Text = frmConsent.FName
.Item("LastName").Range.Text = frmConsent.LName
.Item("Provider").Range.Text = frmConsent.Provider
.Item("Employee").Range.Text = frmConsent.Employee

End With

objWord.PrintOut
objDoc.Close wdDoNotSaveChanges
objWord.Quit



End Sub

Thank You,
 

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