Problem with Ad Hoc Query and Error 3066

C

Carl

I am attempting to build ad-hoc queries using a procedure I borrowed from
“Access 2002 VBAâ€. First I build the SQL string using the following code:

Function BuildSQLString(ByRef strSQL As String) As Boolean
' Temp query to append Masterfile Records to tblMasterHistTemp
Dim strSelect As String, strWHERE As String, strFROM As String, _
strUpdate As String, strDelete As String, strAction As String, _
lngNmbr As Long, strTranHist As String, strMstr As String
strAction = "INSERT INTO tblMasterHistMove "
strFROM = "FROM tblMasterFIle "
strSelect = "SELECT tblMasterFile.* "
strWHERE = "WHERE (((tblMasterFile.Code)='W')); "
strSQL = strAction & strSelect & strFROM & strWHERE
BuildSQLString = True
End Function

In the main code, I call the function using:

If Not BuildSQLString(strSQL) Then
MsgBox ("There was a problem building the SQL string")
MsgBox strSQL
Exit Sub
End If
Set qdfMstr = CurrentDb.CreateQueryDef("", strSQL)
qdfMstr.Execute dbFailOnError
lngRecords = qdfMstr.RecordsAffected
qdfMstr.Close

The problem arises in the “qdfMstr.Execute†line. I get an Error 3066,
“Query must have at least one destination fieldâ€.

If I run the same query using the Query Design (which yields the following
SQL string) it runs fine:

INSERT INTO tblMasterHistMove
SELECT tblMasterFile.*
FROM tblMasterFile
WHERE (((tblMasterFile.CODE)="W"));

So, what am I missing in the function and main code. This is only the
beginning of a series of ad hoc queries I want to build to reduce the number
of saved queries in my database.

Thanks
Carl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top