Word Merge..

CrystalSurfer

Matrix activist
Local time
Today, 09:06
Joined
Jan 11, 2006
Messages
75
Im having a problem getting this code to work.
It is meant to fire up Word (which it does), open up a new doc based on the template (which it also does) and then populate a field in the doc with data from the query table (which it doesn't).

I've put the fields in the Word doc via firstly, defining them as Custom Document Properties in the File, Properties box, and then as "{ DOCPROPERTY "<fieldname>" \*MERGEFORMAT }" codes in the text.

The field in the Word doc is type 'text' and the field in Access is type 'text', so I am stumped by the "Type Mismatch" error it gives when attempting to get/open the recordset.
It hasnt even got to transferring the values across to the doc.?

Ive not done this before (Access newbie) and even found creating the custom fields in Word not as straighforward as I expected!

Please can someone help?

Code:
Private Sub butDocPreview_Click()

   Dim dbs As Database
   Dim objDocs As Object
   Dim objWord As Object
   Dim prps As Object
   Dim rst As Recordset
   Dim strClient As String
   Dim strAccountManager As String

   On Error Resume Next
   Set objWord = GetObject(, "Word.Application")
   If Err.Number = 429 Then
      'Word is not running; creating a Word object
      Set objWord = CreateObject("Word.Application")
      Err.Clear
   End If

   On Error GoTo cmdWord_ClickError
   DoCmd.SetWarnings False
'Open query..
   DoCmd.OpenQuery "qryClientDocHdr_Export"
   intCount = DCount("*", "tmpClientDocHdr")
   Debug.Print "Number of Text items: " & intCount
' Check that there is at least one line..   
   If intCount < 1 Then
      MsgBox "No text to process; cancelling"
      Exit Sub
   End If

   Set dbs = CurrentDb
'==stops here with "Type Mismatch" error==
   Set rst = dbs.OpenRecordset("tmpClientDocHdr", dbOpenDynaset)
   With rst
      strClient = Nz(![Client])
      strAccountManager = Nz(![AccountManager])
   End With
   rst.Close
...
...
...
 
Hi,

What it would appear to be telling you is that there is a problem with the query tmpClientDocHdr. Have you got a parameter in that query where the parameter type doen't match the field type or a join where the fields are of two different types?


K.
 
Actually, I think that since it stops here:

Code:
Set rst = dbs.OpenRecordset("tmpClientDocHdr", dbOpenDynaset)

It would likely be telling you that you are trying to assign an incorrect value to the recordset. It could be that you may want to use:

Code:
Dim rst As DAO.Recordset

otherwise, depending on your version of Access, it could be looking for code that matches an ADO recordset.
 
solution..

Hey guys,
thanks for dropping in.
I managed to solve this by using the following instead:

Code:
With CurrentDb.OpenRecordset("tmpClientWelcomeLetter", dbOpenDynaset)

not sure what the difference meant but it worked! ;)
 

Users who are viewing this thread

Back
Top Bottom