Hi,
I have access 2002 and am trying to modify sql with visual basic. But I get the error 'Query input must contain at least one table or query'. I can't find anything wrong with my string looking at it with a message box so maybe the problem is the query is actually a make table query and I can't set the sql this way. Here is my code:
Set qry = CurrentDb().QueryDefs("qry SelectLisa")
strsql = "INSERT INTO AuditComparisonRecords ( FieldOffice, Physical, Telephone, MailForm, CurMonth, CurYear, CompareMonth )" & _
"SELECT [tbl AuditComparisonRecords].FieldOffice, [tbl AuditComparisonRecords].Physical, [tbl AuditComparisonRecords].Telephone, [tbl AuditComparisonRecords].MailForm, [Forms]![frm AuditProduction]![MyMonth] AS CurMonth, [Forms]![frm AuditProduction]![MyYear] AS CurYear, DateAdd('m',2,[Forms]![frm AuditProduction]![MyDate]) AS CompareMonth" & _
"From [tbl AuditComparisonRecords]WHERE ((([tbl AuditComparisonRecords].FieldOffice)=" & "'" & strCriteria & "'" & "));"
MsgBox strsql
qry.SQL = strsql
Does anyone have any ideas why this will not work?
Thanks
Lisa
I have access 2002 and am trying to modify sql with visual basic. But I get the error 'Query input must contain at least one table or query'. I can't find anything wrong with my string looking at it with a message box so maybe the problem is the query is actually a make table query and I can't set the sql this way. Here is my code:
Set qry = CurrentDb().QueryDefs("qry SelectLisa")
strsql = "INSERT INTO AuditComparisonRecords ( FieldOffice, Physical, Telephone, MailForm, CurMonth, CurYear, CompareMonth )" & _
"SELECT [tbl AuditComparisonRecords].FieldOffice, [tbl AuditComparisonRecords].Physical, [tbl AuditComparisonRecords].Telephone, [tbl AuditComparisonRecords].MailForm, [Forms]![frm AuditProduction]![MyMonth] AS CurMonth, [Forms]![frm AuditProduction]![MyYear] AS CurYear, DateAdd('m',2,[Forms]![frm AuditProduction]![MyDate]) AS CompareMonth" & _
"From [tbl AuditComparisonRecords]WHERE ((([tbl AuditComparisonRecords].FieldOffice)=" & "'" & strCriteria & "'" & "));"
MsgBox strsql
qry.SQL = strsql
Does anyone have any ideas why this will not work?
Thanks
Lisa