I've been throught the forums and they've been most helpful in helping me understand automation but I can't find any thread with a solution to my problem. I want to display the contents of a form that is based on a query, not a base table. I mention this because I'm not certain it isnt relevant. On the click of the button in the Access 2003 form, i can open up word, the right template opens but no form data is passed. I can send static data that I've typed in, but not anything from the form. This is the code, can anyone point out the crucial bit I have got wrong or missed?
"single emq exam query" is the name of the query, and EMQExam is the form.Code:Public Function mergeToWord() On Error Resume Next Dim rsExam As Recordset, iTemp As Integer Set rsExam = DBEngine(0).Databases(0).OpenRecordset("single emq exam query", dbOpenTable) rsExam.FindFirst "[ID]" If rsExam.NoMatch Then MsgBox "Invalid ID Number", vbOKOnly Exit Function End If Dim WordObj Set WordObj = GetObject(, "Word.Application") If Err.Number <> 0 Then Set WordObj = CreateObject("Word.Application") End If WordObj.Visible = True WordObj.Documents.Add Template:="H:\Medicine_Exam.dot", NewTemplate:=False WordObj.Selection.Goto what:=wdGoToBookmark, Name:="record_id" WordObj.Selection.TypeText Forms!EMQexam![ID] DoEvents WordObj.Activate Exit Function End Function
Have I totally mixed it all up?!
Any pointers would be much appreciated.




Reply With Quote