M
Michael
I am having an interesting problem. I am trying to merge
records from my Access database into a Word document. I
have been able to do that successfully by using a query in
Access then using the 'Merge it With MS Word' Officelink.
It merges find and I can see the records appear on the
Word doument.
However, my query is using user input as criteria. For
example, my query uses this line in the criteria line: '>=
[Please enter the label ID that you wish to start printing
from:]'.
Now it works... sometimes. If I open the Word document
manually (ie. opening straight from MS Word), the prompt
will come up and ask me to enter the ID, and then the
records appear correctly, only showing ones of equal or
great value than the entered ID.
However, if I use the command button in my Access form,
the input box will come up, I enter the ID... but the
values and records will always stay the same. One time,
when the input box message was up, I checked the Word
document's records and noticed that records were already
loaded, thus entering anything in the input box would do
nothing.
I am using this code to open the Word document via VB
Code: (note that the function recieves the name of the
file under 'docName')
Private Sub openDoc(docName As String)
Dim objWord As Object, objDoc As Object
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo Err_openDoc
objWord.Visible = True
Set objDoc = objWord.Documents.Open("I:\SOP
Dunwin\Forms\" + _
docName)
Set objWord = Nothing
Set objDoc = Nothing
Exit_openDoc:
Exit Sub
Err_openDoc:
MsgBox Err.Description
Resume Exit_openDoc
End Sub
So, in conclusion, everything works if I open the Word
files manually, but faulter when I try to open them with
VB Code. The file opens fine, but the records do not
appear correctly.
Any help would be appreciated.
records from my Access database into a Word document. I
have been able to do that successfully by using a query in
Access then using the 'Merge it With MS Word' Officelink.
It merges find and I can see the records appear on the
Word doument.
However, my query is using user input as criteria. For
example, my query uses this line in the criteria line: '>=
[Please enter the label ID that you wish to start printing
from:]'.
Now it works... sometimes. If I open the Word document
manually (ie. opening straight from MS Word), the prompt
will come up and ask me to enter the ID, and then the
records appear correctly, only showing ones of equal or
great value than the entered ID.
However, if I use the command button in my Access form,
the input box will come up, I enter the ID... but the
values and records will always stay the same. One time,
when the input box message was up, I checked the Word
document's records and noticed that records were already
loaded, thus entering anything in the input box would do
nothing.
I am using this code to open the Word document via VB
Code: (note that the function recieves the name of the
file under 'docName')
Private Sub openDoc(docName As String)
Dim objWord As Object, objDoc As Object
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo Err_openDoc
objWord.Visible = True
Set objDoc = objWord.Documents.Open("I:\SOP
Dunwin\Forms\" + _
docName)
Set objWord = Nothing
Set objDoc = Nothing
Exit_openDoc:
Exit Sub
Err_openDoc:
MsgBox Err.Description
Resume Exit_openDoc
End Sub
So, in conclusion, everything works if I open the Word
files manually, but faulter when I try to open them with
VB Code. The file opens fine, but the records do not
appear correctly.
Any help would be appreciated.