Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    44

    Unanswered: Error with recordset

    I am trying to do a record set. Not sure why its not working. The error I get is:

    Run time error: '3061'

    Too Few Parameters. Expected 2

    Error is on the set lookupauthorrs ........

    Code below:

    Code:
    Private Sub btnLookUp_Click()
    Dim authorcount As Integer
    
    Dim lookupauthorrs As DAO.Recordset
    Dim lookupauthorSQLSTR As String
    Set db = CurrentDb 'sets the database to the current db
    lookupauthorSQLSTR = "SELECT count(*) FROM dbo_authors WHERE " & _
    "(au_fname = " & [Forms]![frmAuthorLookUp]![txtFirstName] & " AND au_lname = " & [Forms]![frmAuthorLookUp]![txtLastName] & ")"
    
    MsgBox (lookupauthorSQLSTR)
    
    Set lookupauthorrs = db.OpenRecordset(lookupauthorSQLSTR) 'sets sql statement to rs recordset
    authorcount = CInt(lookupauthorrs.Fields(0))
    
    MsgBox ("Author Lookup: " & authorcount)
    
    
    End Sub
    Last edited by tvb2727; 10-27-10 at 15:24.

  2. #2
    Join Date
    Aug 2009
    Location
    Up Nort' Wi
    Posts
    140
    Looks like you're missing your apostrophes before and after the variables.

    ie:
    Code:
    lookupauthorSQLSTR = "SELECT count(*) " _
    &"FROM dbo_authors " _
    &"WHERE (au_fname = '" & [Forms]![frmAuthorLookUp]![txtFirstName] & "' " _
    &"AND au_lname = '" & [Forms]![frmAuthorLookUp]![txtLastName] & "')"
    That error usually occurs when you are trying to send the wrong format (like above) or your field names are misspelled.

    Sam, hth
    Good, fast, cheap...Pick 2.

  3. #3
    Join Date
    Jan 2010
    Posts
    44
    Thanks, that was it. appreciate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •