Results 1 to 5 of 5
  1. #1
    sbfl26 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    2

    OpenRecordset & Data type mismatch run-time error 3464

    Hi,

    I have a search form1, and when user click "ComEdit2" button, it would open another form named "TalentEdit2", and when it loads, the result from search form 1 will go to related field.

    It supposed to be easy since only return records from one field. But it keeps showing run-time error 3464 Data type mismatch in criteria expression and highlight


    "Set RS = CurrentDb.OpenRecordset(strSQL)". I have been searching online and tried all different ways, just not working.

    Also, I would like to know how I can have the field name auto change? Instead of
    Forms![TalentEdit2].test1, test2, test3, I can use
    Forms![TalentEdit2].testi,
    so I can get rid off if statement.

    My code below. Using Access 2016

    Code:
    Private Sub ComEdit2_Click()
        DoCmd.OpenForm "TalentEdit2"
        
        MyID = Me.TalentID
        
        recNo = DLookup("[CatName]", "Category", "TalentID=" & MyID) ' --> trying to find how many record return so it can be use for i loop
        
       Dim RS As DAO.Recordset
       Dim strSQL As String
       
       strSQL = "SELECT CatName FROM Category WHERE TalentID = '" & MyID & "'"
       
       Set RS = CurrentDb.OpenRecordset(strSQL)
       
       For i = 1 To recNo
        If i = 1 Then
            Forms![TalentEdit2].test1 = RS!CatName
        ElseIf i = 2 Then
            Forms![TalentEdit2].test2 = RS!CatName
        Else
            Forms![TalentEdit2].test3 = RS!CatName
        End If
       Next i
        
    End Sub
    Thank you very much...

  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,515
    If the data type of the field is numeric:

    strSQL = "SELECT CatName FROM Category WHERE TalentID = " & MyID

    For the second try:


    Forms![TalentEdit2].Controls(test & i)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,795
    If TalentID is a number type, remove apostrophe delimiters from the SQL.

    If you want a count of records then use DCount("*", "Category", "TalentID=" & MyID). But you don't need this. Just use the recordset RecordCount property. Or: Do While Not rs.EOF

    Dynamically build control name:

    Forms![TalentEdit2].Controls("test" & i)

    There will never be more than 3 records? You have 3 fields with similar data?



    Last edited by June7; 07-25-2019 at 11:49 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    sbfl26 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    2
    Thank you very much, it works perfect. Here is the update.

    Private Sub ComEdit2_Click()

    DoCmd.OpenForm "TalentEdit2"

    MyID = Me.TalentID


    Dim RS As DAO.Recordset
    Dim strSQL As String

    strSQL = "SELECT CatName FROM Category WHERE TalentID = " & MyID

    Set RS = CurrentDb.OpenRecordset(strSQL)

    i = 1
    Do While Not RS.EOF
    Forms![TalentEdit2].Controls("test" & i) = RS!CatName
    i = i + 1
    RS.MoveNext
    Loop

    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,515
    Happy to help and welcome to the site by the way!
    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. Error 3464 data type mismatch in Visual Basic
    By russianthistle in forum Access
    Replies: 20
    Last Post: 02-11-2019, 08:39 PM
  2. Replies: 8
    Last Post: 03-14-2017, 02:36 PM
  3. Replies: 2
    Last Post: 08-24-2015, 09:14 PM
  4. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  5. Error 3464 - Data type mismatch
    By JustLearning in forum Forms
    Replies: 1
    Last Post: 01-18-2013, 08:31 PM

Tags for this Thread

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