Alfredo Ramirez
Alfredo Ramirez

Reputation: 11

run time error 3061 - ms access

I am relatively new to MS Access and VBA. I am trying to do a bit of code for this DB and get error message 'Run Time Error 3061. Too Few parameters. Expected 1" when it gets to the OpenRecordSet clause.

I have been researching and looking at this for days but cannot figure out the reason for the error. I know the error is in the SELECT specifically in the WHERE clause when the form is being closed.

The strange thing is that when i change the condition to Record_Num = 2 or any specific number it seems to work, but i need to use the Record_Match_Temp variable.

Any help will be appreciated. Thanks in advance. Here is the code

Option Compare Database
    Dim Record_Match_Temp As Integer
    Dim Logged_Now As String


Private Sub Form_Close()
    Dim db2 As Database
    Dim rs2 As Recordset2
    Dim SelStr As String

    Set db2 = CurrentDb()
    SelStr = "SELECT Record_Num FROM User_Log WHERE Record_Num = Record_Match_Temp"

    Set rs2 = db2.OpenRecordset(SelStr)

 End Sub

Private Sub Form_Load()
    Form_User_Name = Environ("UserName")
    Logged_Now = Now()

    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb()

    Set rs = db.OpenRecordset("Select * from [User_Log]")

    rs.AddNew
    rs![Log_User_Name] = Environ("UserName")
    rs![Logged_Computer] = Environ("ComputerName")
    rs![Logged_In] = Logged_Now
    rs![Record_Match] = rs![Record_Num]
    Record_Match_Temp = rs![Record_Num]
    ' rs![Logged_Out] = Now()
    rs.Update

 End Sub



Private Sub Form_Timer()
  Date_Time.Requery

End Sub

Upvotes: 0

Views: 3145

Answers (1)

Tim Williams
Tim Williams

Reputation: 166790

SelStr = "SELECT Record_Num FROM User_Log WHERE Record_Num = " & _
                                                  Record_Match_Temp

Add single quotes around Record_Match_Temp if the field is not numeric.

Upvotes: 1

Related Questions