Error 5941

Solved
omar_einstein -  
 omar_einstein -
Hello,
I am currently developing a CMMS application in VBA.
The problem is that I want to transfer the data stored in a recordset to a Word file.
Every time I run my code, error 5941 occurs: "The requested collection member does not exist."
Here is my code:

Private Sub Transfer_Click()
Dim wApp As Object
Dim chemin As String
Dim path As String
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim sql As String
sql = "SELECT num, nom, dat_pan, heu_deb, heu_fin from test"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql)
Set wApp = CreateObject("Word.Application")
chemin = Application.CurrentProject.path
path = "" & chemin & "" + "/Recepisse.doc"
wApp.Visible = True
While Not rs.EOF
With wApp
.Documents.Open (path)
.ActiveDocument.Bookmarks("num").Range.Text = rs.Fields("num") **Problem**
.ActiveDocument.Bookmarks("nom").Range.Text = rs.Fields("nom")
.ActiveDocument.Bookmarks("dat_pan").Range.Text = rs.Fields("dat_pan")
.ActiveDocument.Bookmarks("heu_deb").Range.Text = rs.Fields("heu_deb")
.ActiveDocument.Bookmarks("heu_fin").Range.Text = rs.Fields("heu_fin")
.ActiveDocument.PrintOut
.ActiveDocument.Close (wdDoNotSaveChanges)
End With
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Set wApp = Nothing
End Sub

The problem occurs on the line marked "Problem."
Please let me know the solution, as I am stuck at this step.
Thank you in advance for the attention you will give to my message.
Configuration: Windows XP Internet Explorer 7.0

14 réponses

lermite222 Posted messages 9042 Status Contributeur 1 199
 
Hello,
I think the line just below Open is missing:
.document.visible = True
See you later
--
Experience teaches more surely than advice. (André Gide)
If you bump into a pot and it sounds hollow, it’s not necessarily the pot that is empty. ;-)(Confucius)
0
omar_einstein
 
Hello friend,
Thank you first for the attention you paid to my message.
I tried the trick you mentioned but in vain.
The compiler displays the following message: "Property or method not handled by this object" error code: "438"....
Please respond to me as soon as possible with other tips.
0