I have inherited a database written on access 95, I am currently using access 2002 and I am running on that with only 1 major problem. There is a document generate function which merges query data into a word doc (originally word 95, now using office xp). The function saves the query results using fill cache then opens and merges to the document selected. The document opens okay but the data does not populate the document. The generate selection button runs the following (I have edited it to show only one specific document, there are others but the mechanics are basically the same):
Private Sub cmd_generatedefdocs_Click()
On Error GoTo Err_cmd_generatedefdocs_Click
DoCmd.Hourglass True
Dim lrv As Integer
lrv = 0
DoEvents
If Me!opt_b6show Then lrv = lrv + printmanifest(Forms!sfrm_createdefinitedocuments!t xtrefno, objword, constShowFirst)
If Me!opt_b6print Then lrv = lrv + printmanifest(Forms!sfrm_createdefinitedocuments!t xtrefno, objword, constPrintDirect)
DoEvents
DoCmd.Hourglass False
If lrv > 0 Then
Forms!sfrm_createdefinitedocuments!cmd_closedefdoc s.SetFocus
Forms!sfrm_createdefinitedocuments!cmd_generatedef docs.Enabled = False
objword.AppShow
Else
MsgBox "No Documents to Show."
End If
Exit_cmd_generatedefdocs_Click:
Exit Sub
Err_cmd_generatedefdocs_Click:
MsgBox Err.Description
Resume Exit_cmd_generatedefdocs_Click
End Sub
The Printmanifest function is:
Function printmanifest(tourid As Integer, wordobject As Object, printornot As Integer)
On Error Resume Next
Dim varcopies As Integer
Dim varcollate As Integer
varcopies = 2
varcollate = 1
Dim ldb As Database
Dim lqdf_b6c As QueryDef
Dim lsqlstmt As String
Set ldb = CurrentDb
printmanifest = 1
DoEvents
Dim seats As String
seats = InputBox("Please enter number of seats on the coach", "Create Passenger Manifest")
Set lqdf_b6c = ldb.QueryDefs!qry_b6
' locate the coach booking record
lqdf_b6c.SQL = "SELECT DISTINCTROW tbl_pb.FromDate, tbl_pb.ToDate, tbl_pb.PartyName, tbl_pb.PLTitle, tbl_pb.PLInitial, tbl_pb.PLSurname, tbl_pb.RefNo, tlkpdestinations.Suffix, tlkpdestinations.Destination, tbl_pb.CrossingOutDate, tbl_pb.CrossingInDate FROM tlkpdestinations INNER JOIN tbl_pb ON tlkpdestinations.ID = tbl_pb.DestinationID WHERE (((tbl_pb.RefNo)=" & tourid & "));"
lqdf_b6c.Close ' close the querydef
' reopen the query def and get some data from it
DoEvents
Dim lrset_b6c As Recordset
Set lrset_b6c = ldb.OpenRecordset("qry_b6", DB_OPEN_SNAPSHOT)
lrset_b6c.FillCache
lrset_b6c.Close
DoEvents
Set lrset_b6c = ldb.OpenRecordset("qry_b6", DB_OPEN_SNAPSHOT)
If lrset_b6c.RecordCount > 0 Then
wordobject.FileOpen DocumentPath & "b6merge.doc"
wordobject.MailMergeToDoc ' merge the file with the data provided.
wordobject.StartOfDocument
seats = LTrim(Str(Val(seats) + 1))
wordobject.editfind Find:=seats, Direction:=0, WholeWord:=1
Dim extraseats As Integer
Dim i As Integer
extraseats = 78 - Val(seats)
For i = 1 To extraseats
wordobject.TableDeleteRow
Next i
If wordobject.editfindfound() Then
MsgBox "Found it, should be on it"
End If
' Changes the size and position of the (R) in Disneyland
dothedisneything wordobject
If printornot = constPrintDirect Then
printmanifest = printinword(wordobject, varcopies, varcollate)
Else
'Sets the return value of the function to true, as if we get
'this far, we've completed
printmanifest = 1
End If
Else
MsgBox "Missing details. Please check and try again."
End If
End Function
Now, to my limited knowledge there is no reason why this should not work (the Documentpath is correct as the document is found and opened).
Is it an incompatability between the original and office xp, I have tried all I know and it is driving me bonkers, so any suggestions would be very much appreciated. This dbase is to be replaced at a later date, but I need to get it to work so that it can be used until then.
As a note, the original dbase and merge documents were held on a server with users having their own desktops, and all was well, now the whole system has been replaced and all users are using terminal services, the drive name stayed the same, the merge documents were replaced on to the drive. I do not know whether there were templates, or whether templates were needed. To me there seems to be a link missing somewhere, I have not had much to do with mail merge docs before (prefer reports) so I am trying to climb a steep curve and any assistance would be great.
I have now sorted this problem, it turned out to be a few things, firstly made sure the correct references were selected (ie word 10.0), then compiled te Dbase which showed up a number of arguments that 2002 did not like, after amending these I then had to use the work around by microsoft
http://support.microsoft.com/?kbid=825765 (registry entry), this was because of SP3 which played threw in some spanners. Then re-linked docs to data source. All this worked a treat.