I am using Access 2007.
I have a report that actually opens a WORD file that contains the report instead of using the Access report writer. I setup the WORD file so that the merge fields come from a query in Access called qry007. When I call for the report from a form in Access, heres what happens.
A report dialog is opened where the user enters the criteria for the query that feeds the report. The whole purpose of this dialog is to simply change the actual query statement associated with qry007, which it does. I know that this part of the code is working correctly because after closing the dialog, if I open qry007 in interactive Access, I see the changes are there as intended.
After doing the above I run the code listed below. This code opens the WORD file, which is linked to the Access query. The problem is that I dont see the changes in the Word file. That is, the word file is using old criteria from qry007. If I close the word file and then reopen it (interactively from within word) , I get a dialog telling me that its going to run qry007 and when I select OK, the word file opens with the correct data. In other words, I have some sort of latency problem. The change has actually been made to the underlying query, but the word file does not reflect this, unless I open it twice. I suspect the problem is in the code that follows. This code is run after the dialog close. I was wondering if someone would take a look at it and see if they see the problem
Thank you.
Dim objWORD As Object
Dim strWordFile
'Invoke error handling
On Error GoTo CreateWORDObj_Err
'Create in code a reference to Excell 2007
Set objWORD = CreateObject("WORD.Applica
tion")
strWordFile = CurrentProject.Path
strWordFile = strWordFile & "\Word Test01.docx"
With objWORD
.Documents.Open strWordFile
'Give the document time to open
DoEvents
'.ActiveDocument.PrintPrev
iew
.Visible = True
End With
Set objWORD = Nothing
CreateWordObj_Exit:
Exit Sub
CreateWORDObj_Err:
'If an error occurs, display a message and return false
MsgBox "Couldn't Launch WORD!!", vbCritical, "Warning!!"
Set objWORD = Nothing
Resume CreateWordObj_Exit
Start Free Trial