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.

S. Jackson
 
D

Dave Jones

What does the error message say?

Are the other users mapped to the network drive using M:\
or are they mapped as E:\ or something else?
If not M:\, an error will occur.
Much better to use the UNC path in your code as this is
not affected if the drive mapping changes.

Dave
-----Original Message-----
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
 
S

Shelly Jackson

Dave:

Yes, the other users are mapped using drive M.

What is the UNC path?

S. Jackson
 

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