VBA CODE - PLS HELP

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. The user is mapped
to the M: drive as I am. The only difference is that the user has Office 97
and I have Office 2000. Could this be the problem?



S. Jackson
 
S

S Jackson

Okay! I figured out the problem:

When I created the template on my computer, I also created a macro that runs
when the template opens. The error the other users are getting is a
Run-time error - unable to run macro. So, I know what the problem is: The
template stored out on the LAN does not have the macro attached to it. How
do I attach the macro to the template?

Thanks all!

S. Jackson
 
S

S Jackson

I had two different people attempt to run the event below. The first user
gets an error about not finding the correct path. Debug window has this
line of the code highlighted: objWord.Documents.Add
M:\LTCR\Legal\FormLetter.dot" This user is using Office 97. The template
and code was created using Office 2000

The second user got a Runtime error - couldn't find the macro. The second
user is using Office 2000. I got this problem fixed when I figured out how
to copy the macro the template was looking for.

However, is there a fix for the first user? The path is correct. He is
mapped to the M:drive. I am not understanding this error unless it has to
do with the fact that I am using Office 2000 and he is using Office 97.

I'm lost, please help. Thanks.

S. Jackson
 
C

Chris

It sounds like the error is the same on both machines,
just that 2000 is interpreting it differently.

Move the macro from the template to the calling code.
Redo the variables, and you might be better off.


Chris
 
S

S Jackson

Hi Chris:

Thank you for your response. I'll see if I can muddle through your
suggestion. I'm pretty green at all this, unfortunately, and I barley grasp
what you are telling me to do. I think you want me to put the "directions"
of the macro right into the code?

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