Search code examples
sqlvbams-access

How can i properly use DLookup function to return strings?


Dim gen as String

gen = DLookup("gender", "Patient", "ID_patient='" & Me.ComboPatients.Value & "'")

I get error runtime 3464 for mis-match-type data and i don't know why?


Solution

  • Data mismatch error occurs if ID_patient is a number type field. Do not use apostrophe delimiters for number type, only text type field. Use # for date/time type field parameters.

    From your comment (should have edited question or started a new one), concatenation is not correct. AND must be included in literal string parts - will not be colored blue. Consider:

    "age='young (0-30)' AND ID_par=" & Me.ComboPatients & " AND gender='male'"
    

    or rearrange:

    "age='young (0-30)' AND gender='male' AND ID_par=" & Me.ComboPatients