Please Help With VBA Code

S

S Jackson

I have a database that is stored on our LAN that is accessed by three
different users.

In the database I have a form that contains a button that has the following
OnClick Event:

Dim objWord As Object

'Open Microsoft Word using automation

Set objWord = New Word.Application

objWord.Documents.Add "M:\LTCR\Legal\FormLetter.dot"
objWord.Visible = True

'The Following code is generated from your access form while it is
manipulating an instance of Word.
'So, while it looks somewhat live VBA, it's really Word VBA.

Line1: objWord.ActiveDocument.Bookmarks("Representative").Range.Text =
Me!Representative

Line2: objWord.ActiveDocument.Bookmarks("RepAddy").Range.Text =
Me!RepAddress

Line3: objWord.ActiveDocument.Bookmarks("Case").Range.Text = Me!CaseName

Line4: objWord.ActiveDocument.Bookmarks("DHSNo").Range.Text = Me!DHSNo

If IsNull(Me!RepFax) Then
objWord.ActiveDocument.Bookmarks("Fax").Range.Text = ""
Else
objWord.ActiveDocument.Bookmarks("Fax").Range.Text = "VIA FACSIMILE " &
Me!RepFax
End If

End Sub

**********
As you can see Word is suppose to start and open up a template called
"FormLetter" which is stored on the same drive as the database (the LAN
drive, M:, that all three users have access too) and collect specific
information from Access and put it into the Word template called FormLetter.
This function works beautifully for me on my machine and I also happen to be
the one that designed the template and stored it out on the Lan - M: drive.
However, when another user at a different work station clicks the button we
get an error. On Debug the line, "objWord.Documents.Add
"M:\LTCR\Legal\FormLetter.dot" is highlighted. Why is the code stopping
here? The path to the template FormLetter is correct and the user has
access to the M:drive (remember the database itself is also stored under the
same path).

Any help would be greatly appreciated. Thank you.
 
J

John Nurick

Try this.

1) Fire up Word on one of the other computers.
2) Hit Alt-F11 to display the VBE and (if necessary) Ctrl-G to get the
Immediate pane.
3) Run the command
Application.Documents.Add "M:\LTCR\Legal\FormLetter.dot"

If this doesn't work, perhaps the computer is using a different drive
letter for the network share.


I have a database that is stored on our LAN that is accessed by three
different users.

In the database I have a form that contains a button that has the following
OnClick Event:

Dim objWord As Object

'Open Microsoft Word using automation

Set objWord = New Word.Application

objWord.Documents.Add "M:\LTCR\Legal\FormLetter.dot"
objWord.Visible = True

'The Following code is generated from your access form while it is
manipulating an instance of Word.
'So, while it looks somewhat live VBA, it's really Word VBA.

Line1: objWord.ActiveDocument.Bookmarks("Representative").Range.Text =
Me!Representative

Line2: objWord.ActiveDocument.Bookmarks("RepAddy").Range.Text =
Me!RepAddress

Line3: objWord.ActiveDocument.Bookmarks("Case").Range.Text = Me!CaseName

Line4: objWord.ActiveDocument.Bookmarks("DHSNo").Range.Text = Me!DHSNo

If IsNull(Me!RepFax) Then
objWord.ActiveDocument.Bookmarks("Fax").Range.Text = ""
Else
objWord.ActiveDocument.Bookmarks("Fax").Range.Text = "VIA FACSIMILE " &
Me!RepFax
End If

End Sub

**********
As you can see Word is suppose to start and open up a template called
"FormLetter" which is stored on the same drive as the database (the LAN
drive, M:, that all three users have access too) and collect specific
information from Access and put it into the Word template called FormLetter.
This function works beautifully for me on my machine and I also happen to be
the one that designed the template and stored it out on the Lan - M: drive.
However, when another user at a different work station clicks the button we
get an error. On Debug the line, "objWord.Documents.Add
"M:\LTCR\Legal\FormLetter.dot" is highlighted. Why is the code stopping
here? The path to the template FormLetter is correct and the user has
access to the M:drive (remember the database itself is also stored under the
same path).

Any help would be greatly appreciated. Thank you.

John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 

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