Export records to word bookmarks (1 Viewer)

Lochwood

Registered User.
Local time
Today, 05:27
Joined
Jun 7, 2017
Messages
130
I have a module which looks at a query that has 3 records. i am trying to input this data into a single word document setup with bookmarks. Getting error 3061 too few parameters. Expected 1. Any help would be appreciated.

Public Sub ExportCVToWord()

Dim wApp As Word.Application
Dim WDoc As Word.Document
Dim rs As DAO.Recordset

Set wApp = Word.Application
Set WDoc = wApp.Documents.Open("S:\CV\CV -Blank.docx")
Set db = CurrentDb

Set rs = db.OpenRecordset("Select * from Qualifications_Selected_Individual_For_NEWCV")


rs.MoveFirst

'Do Until rs.EOF
WDoc.Bookmarks("Name").Range.Text = Nz(rs!Name, "")
WDoc.Bookmarks("Qualifications").Range.Text = Nz(rs!Qualification, "")

rs.MoveNext

WDoc.Bookmarks("Qualifications2").Range.Text = Nz(rs!Qualification, "")

rs.MoveNext

WDoc.Bookmarks("Qualifications3").Range.Text = Nz(rs!Qualification, "")
WDoc.SaveAs2 "C:\Users\temp\Documents\CVs" & rs!Name & "_CV.Docx"




'Loop

WDoc.Close False
wApp.Quit

Set WDoc = Nothing
Set wApp = Nothing
Set rs = Nothing

'WDoc.Bookmarks("Name").Range.Delete wdCharacter, Len(Nz(rs!Name, ""))
'WDoc.Bookmarks("Qualification").Range.Delete wdCharacter, Len(Nz(rs!Qualification, ""))

End Sub
 

Cronk

Registered User.
Local time
Today, 22:27
Joined
Jul 4, 2013
Messages
2,772
On what line does the error occur? Does your query require a parameter input?


Incidentally, you declare all other variables but not db. Any reason for not having explicit variable declarateion?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:27
Joined
Aug 30, 2003
Messages
36,125
Does the query have a form parameter? If so, simplest solution is to wrap it in the Eval() function.
 

Lochwood

Registered User.
Local time
Today, 05:27
Joined
Jun 7, 2017
Messages
130
yes the query does have a par to a form. I am not familiar with the eval()

Fails here: Set rs = db.OpenRecordset("Select * from Qualifications_Selected_Individual_For_NEWCV")
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:27
Joined
Feb 28, 2001
Messages
27,156
As long as you don't have Option Explicit enabled, it doesn't matter that "db" isn't pre-defined. You do assert a value for it that is legit. The call to db.OpenRecordset is syntactically correct in that the 2nd, 3rd, and 4th arguments are optional. Taking the default for 2nd argument when the first argument is an SQL statement simply means you would get back a dynaset, which is also OK.

Therefore, I am inclined to say that the problem must be in the query. If you open that query directly, does it return records?

Failing that, make that call have an explicit recordset type of dbOpenDynaset (2nd argument) and see if it makes any difference whatsoever, even if only changing the error number.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:27
Joined
Aug 30, 2003
Messages
36,125
OpenRecordset can't resolve the form reference; it's a known issue. In the query, replace

Forms!FormName.ControlName

with

Eval('Forms!FormName.ControlName')

There are other solutions, but in my mind this is the simplest.
 

Lochwood

Registered User.
Local time
Today, 05:27
Joined
Jun 7, 2017
Messages
130
OpenRecordset can't resolve the form reference; it's a known issue. In the query, replace

Forms!FormName.ControlName

with

Eval('Forms!FormName.ControlName')

There are other solutions, but in my mind this is the simplest.

PBaldy, yes this worked by adding Eval to criteria in Query.. thanks everyone for your input.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:27
Joined
Aug 30, 2003
Messages
36,125
Happy to help.
 

Users who are viewing this thread

Top Bottom