Run-time error '3464' - Data type mismatch in criteria expresssion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SourceOfAccess
    New Member
    • Nov 2015
    • 6

    Run-time error '3464' - Data type mismatch in criteria expresssion

    So...I'm trying to create a field that automatically calculates a value by gathering data from multiple tables.

    My code seems to be fine, but MS Access returns with an error:

    Run-time error '3464' - Data type mismatch in criteria expresssion

    My code is as following:
    Code:
    Dim AccommodationType As String
    
    AccommodationType = DLookup("AccommodationType", "Accommodations", "AccommodationID = '" & Me.Accommodation.Value & "'")
    For your reference:

    1. The error occurs on the second line of the code (DLookup)
    2. The data type for the field: "AccommodationT ype" is Number
    3. The data type for the field: "AccommodationI D" is Number
    4. The data type for the field: "Me.Accommodati on.Value" is Number

    Any ideas?
    Last edited by zmbd; Dec 3 '15, 11:10 PM. Reason: [z{code formatted}]
  • mbizup
    New Member
    • Jun 2015
    • 80

    #2
    Delimiters...

    Text uses quotes
    Dates use hash marks (#)
    Numbers - no delimiters

    so your syntax should be (drop the single quotes since AccommodationID is a numeric field):
    Code:
    AccommodationType = DLookup("AccommodationType", "Accommodations", "AccommodationID = " & Me.Accommodation.Value)

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      You might want to consider building your strings first too:

      So:
      Code:
      Dim AccommodationType As String
      
      AccommodationType = DLookup("AccommodationType", "Accommodations", "AccommodationID = '" & Me.Accommodation.Value & "'")
      goes to:

      Code:
      Dim zCondition as string
      '
      zCondition = "AccommodationID = '" & _
          Me.Accommodation.Value & "'"
      '
      'Debug.Print "zCondition = " & zCondition 'uncomment to debug
      '
      DLookup("AccommodationType", _
          "Accommodations", _
           zCondition)
      Most Dlookup errors occur from a malformed conditional string which is difficult to troubleshoot when built witin the function.

      -z

      Comment

      Working...