Results 1 to 2 of 2
  1. #1
    coilerDH is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Dec 2014
    Posts
    13

    Help with a data type mismatch in a Recordset.FindFirst method

    I have a form. It has a combo box for persons last name. The form also has a button called client search. I have some code that I pieced together from reading online.


    A name is selected from the combo box, you hit the search button and a form will be launched with the selected persons information. It works fine. The data I'm working with in my table is ID(text), FirstName(text), LastName(text). I want the ID in the table to be an number. If I change the data type to a number I get the mismatch error. I don't know enough about VB to figure this out. Help would be appreciated.

    Private Sub Command4_Click()


    Dim strSQL As String
    If Not Nz(cbxLastName) = "" Then strSQL = strSQL & " And [LastName]='" & cbxLastName & "'"


    strSQL = Mid(strSQL, 6)


    If strSQL = "" Then
    MsgBox "Please enter at least one criteria field.", vbExclamation
    Exit Sub
    End If


    Dim strID As String
    strID = Nz(DLookup("ID", "[Table1]", strSQL))
    If strID = "" Then
    MsgBox "No match!", vbExclamation
    Exit Sub
    End If


    FindClient "Client Auth Info", strID




    End Sub




    Private Sub FindClient(strFormName, strID As String)
    DoCmd.OpenForm strFormName
    Dim rs As Recordset
    Set rs = Forms(strFormName).RecordsetClone
    rs.FindFirst "ID='" & strID & "'"
    If Not rs.NoMatch Then Forms(strFormName).Bookmark = rs.Bookmark


    End Sub

    The bolded line. Run time error 3464: Data type mismatch in criteria expression.
    Works with ID field as text, error when set as number. I would like this to work with the ID data type as number.
    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    For a numeric data type you drop the delimiters:

    rs.FindFirst "ID=" & strID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-21-2014, 09:14 AM
  2. Data Type Mismatch
    By Mtyetti2 in forum Queries
    Replies: 3
    Last Post: 10-23-2013, 11:48 AM
  3. FindFirst Not Working with Decimal Data Type
    By JonMulder in forum Programming
    Replies: 5
    Last Post: 01-22-2013, 01:26 PM
  4. Data Type Mismatch
    By timmy in forum Programming
    Replies: 9
    Last Post: 04-12-2011, 03:48 AM
  5. data type mismatch
    By jgelpi16 in forum Programming
    Replies: 5
    Last Post: 08-02-2010, 04:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums