Run-time error 3061

TomJ58

Registered User.
Local time
Today, 10:11
Joined
Dec 13, 2012
Messages
28
Hi all,

I have VBA code tied to an Add Record Command button. However, when the SQL string is executed, the error message "Run-time error 3061. Too few parameters. Expected 3." is displayed. I have reviewed the SQL string for mismatch parenthesis, but cannot find any. Any help in solving this would be appreciated.

Code:
Private Sub AddRecord_Exit(Cancel As Integer)
    Dim db As DAO.Database
    Dim fldActive As String
    Dim fldSysadd As String
    Dim fldRetire As String
    Dim strSQL As String
    
    fldActive = "Active"
    fldSysadd = "System Added"
    fldRetire = "Retired"
    
    Set db = CurrentDb
    
    strSQL = "INSERT INTO tblAuditJobsMaster ( CoStarID ) " & _
             "SELECT tblCostarJobMaster.JobID " & _
             "FROM tblCostarJobMaster " & _
             "LEFT JOIN tblAuditJobsMaster " & _
             "ON tblCostarJobMaster.[JobID] = tblAuditJobsMaster.[CoStarID] " & _
             "WHERE (((tblAuditJobsMaster.CoStarID) Is Null) " & _
             "AND ((tblCostarJobMaster.JobStatus)=fldActive Or (tblCostarJobMaster.JobStatus)=fldSysAdd Or (tblCostarJobMaster.JobStatus)=fldRetire))" & ";"
    
    DoCmd.SetWarnings False
    db.Execute strSQL
    DoCmd.SetWarnings True
    
    db.Close
End Sub
 
How many fields does the table tblAuditJobMaster have? Just one field? Because INSERT INTO creates a new ROW in the table.. Based on the error I think you are missing the other two fields of the table.. Have they been set as REQUIRED?
 
I do not think the error is related to the number of fields in the Audit table. The table being updated contains 10 fields, but I only want to populate the foreign key field in the child table when the master table has a new record added to it.

I do not understand why this code did not work. When I execute the same query using the DoCmd.execute "QUERY NAME" code, the query works properly.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom