Export records to word bookmarks

Lochwood

Registered User.
Local time
Today, 00:33
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
 
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?
 
Does the query have a form parameter? If so, simplest solution is to wrap it in the Eval() function.
 
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")
 
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.
 
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.
 
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.
 

Users who are viewing this thread

Back
Top Bottom