Results 1 to 11 of 11
  1. #1
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55

    Newbie having trouble with data type mismatch error...

    I'm very new to Access programming, so pardon my ignorance! I "borrowed" some code to make a log in form work and it seemed to run okay until it got to the following:

    If Me.txtPassword.Value = DLookup("Emp_Pass", "tblEmployeeRoster", _


    "[Emp_ID]=" & Me.cboIdentity.Value) Then

    The error message I got was, "Run-time error '3464': Data type mismatch in criteria expression." [Emp_ID] is formatted as a text field. Emp_Pass is formatted as text.

    I've spent nearly 2 hours trying to fix the problem to no avail. Thought I would give this forum a try (my very first time). Any help/clues would be greatly appreciated!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What is the bound field of Me.cboIdentity? What field type is the bound field?

    If, in the table, "Emp_ID" is a Long number type, then the bound column (field) in Me.cboIdentity must be a Long.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    See here for the syntax adjustment for a text field:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Hi Steve -

    The bound field is Emp_ID from that same table (tblEmployeeRoster); so, the combo box itself shows 3 fields from that table (Last_Name, First_Name, and Emp_ID) with that third one (Emp_ID) bound. The field type for that should be the same, right? I checked the Properties for that field in the query for the Row Source of that combo and it doesn't say anything...

  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,652
    I wonder if I should post the link again...nah, he'll see it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    That worked! I tried mimmicking your example:

    If Me.txtPassword.Value = DLookup("Emp_Pass", "tblEmployeeRoster", _
    "[Emp_ID] = '" & Me.cboIdentity.Value & "'") Then

    Thanks so much!!!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help! I suspect Steve missed this in the OP: "[Emp_ID] is formatted as a text field".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I suspect Steve missed this in the OP: "[Emp_ID] is formatted as a text field".
    I saw that but wasn't sure if the field [Emp_ID] was actually numeric. If [Emp_ID] is the PK, having the field type of text is problematic (from what I have read).
    And if [Emp_ID] was text, my next reply was going to be about delimiters.

  9. #9
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Steve, what's wrong with having Emp_ID (which is the PK) as text (just curious)?

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    A TEXT field can be up to 255 characters long (Access 2000), which would make for a crazy long key comparison. (main reason)

    Trouble with sorting. I entered these text strings and sorted them. Since text is sorted left to right.... this what you get.

    A1
    A100
    A11
    A2
    A20
    A22
    A300
    A34
    A45

    Will/could an employee's Emp_ID ever change?

    Also, see:
    http://www.bluemoosetech.com/microso...ial.php?jid=54
    http://www.fmsinc.com/free/newtips/primarykey.asp

    Much easier (for me) to use an autonumber as the PK.

  11. #11
    David618 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    55
    Thanks, Steve -

    I see your point. In this case, the ID would never change - is unique and assigned by the company, which is what I have to use. If it were up to me, I probably would use the autonumber.

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

Similar Threads

  1. Data type mismatch error
    By Tomfernandez1 in forum Programming
    Replies: 5
    Last Post: 10-05-2012, 07:27 AM
  2. Data type mismatch error
    By nigelbloomy in forum Programming
    Replies: 1
    Last Post: 08-01-2012, 09:19 AM
  3. Replies: 1
    Last Post: 05-11-2012, 10:59 AM
  4. Newbie. DLookup gives type mismatch error.
    By graffiti in forum Programming
    Replies: 4
    Last Post: 12-13-2011, 05:22 AM
  5. Data type mismatch error
    By AccessUser123 in forum Queries
    Replies: 1
    Last Post: 05-22-2011, 07:48 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