PDA

View Full Version : Solved: Error 3061 Too few Parameters problem



majaro
01-18-2008, 07:33 AM
I'm trying to append a record from one table to another then delete the record. I know I could just flag the record but this is not what is required. The following code compiles but erors out.

Private Sub cmdDelete_Click()
On Error GoTo Err_DoArchive
Dim ws As DAO.Workspace 'Current workspace (for transaction).
Dim db As DAO.Database 'Inside the transaction.
Dim bInTrans As Boolean 'Flag that transaction is active.
Dim strSql As String 'Action query statements.
Dim strMsg As String 'MsgBox message.
'Step 1: Initialize database object inside a transaction.
Set ws = DBEngine(0)
ws.BeginTrans
bInTrans = True
Set db = ws(0)
'Step 2: Execute the append.
strSql = "INSERT INTO ArchivedStatusReports ( Reports.ReportNo, Reports.ProjId, Reprts.ReportDate, Reports.Report ) " & _
"IN ""F:\PIDDelete\PID_Work_Grid011407.mdb"" " & _
"SELECT ReportNo, ProjId, ReportDate, Report FROM Reports WHERE (MyYesNoField = True);"
db.Execute strSql, dbFailOnError
'Step 3: Execute the delete.
strSql = "DELETE FROM Reports WHERE (MyYesNoField = True);"
db.Execute strSql, dbFailOnError
'Step 4: Get user confirmation to commit the change.
strMsg = "Archive " & db.RecordsAffected & " record(s)?"
If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
ws.CommitTrans
bInTrans = False
End If
Exit_DoArchive:
'Step 5: Clean up
On Error Resume Next
Set db = Nothing
If bInTrans Then 'Rollback if the transaction is active.
ws.Rollback
End If
Set ws = Nothing
Exit Sub
Err_DoArchive:
MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
Resume Exit_DoArchive

End Sub

Here are the table fields

ArchivedStatus Reports

ReportNo
ProjId
ReportDate
Report

Reports

ReportNo *Auto num field
ProjId
ReportDate
Report

I looked on the net for an explaination of that error. Didn't find anything useful. I didn't think that the query is asking for a parameter. :dunno

akn112
01-23-2008, 08:33 AM
the error usually means you are inputting too few/many fields (ie:input 3 fields but only gave it 2 or something similar). My guess would be you cannot manually input the autonumber. those will be generated automatically when input. Also, i'm unsure why you have prepended your output fields with "reports."

when you say INSERT INTO ArchivedStatusReports ([field1],[field2])
it's assuming those fields are from ArchivedStatus Reports

saying INSERT INTO ArchivedStatusReports ( Reports.ReportNo, Reports.ProjId, Reprts.ReportDate, Reports.Report )
is kind of contradictive in itself.

HTH =)

Edit:

Just a quick suggestion. when typing quotations inside quotations its usually cleaner to use single quote ie: "INSERT INTO tblTest([field1]) VALUES('mystring')" rather than
"INSERT INTO tblTest([field1]) VALUES(""mystring"")"