Error 5941
Solved
omar_einstein
-
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.
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
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.