Results 1 to 5 of 5
  1. #1
    graffiti is offline Newest Newbie ever
    Windows XP Access 2003
    Join Date
    Nov 2011
    Location
    Worthing, south coast of the UK
    Posts
    21

    Newbie. DLookup gives type mismatch error.


    Hi again.

    I hate asking silly questions, but I can't ask anyone else at the moment. This will be another basic Q I'm sure.

    The following DLookup gives me a "Data type mismatch in criteria expression" error. I can't see where...


    Code:
     
    Dim varUserID As Long
    Dim varUserPassword As String
     
    varUserPassword = DLookup("[Password]", "tblDBUsers", "[ID] = '" & varUserID & "'")


    So that is...

    Code:
     
    string = dlookup ( string, table, [Long] long)
       1                 1              2       2
    ID is a field in a table set to autonumber which is defined as Lond Integer.
    Password is a field in a table set to text with [20] characters. It's also a Primary Key.

    So 1 and 1 matches, 2 and 2 matches. Please educate me, where is the mismatch please?
    Last edited by graffiti; 12-13-2011 at 05:22 AM.

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Try

    Quote Originally Posted by graffiti View Post
    Hi again.

    I hate asking silly questions, but I can't ask anyone else at the moment. This will be another basic Q I'm sure.

    The following DLookup gives me a "Data type mismatch in criteria expression" error. I can't see where...


    Code:
     
    Dim varUserID As Long
    Dim varUserPassword As String
     
    varUserPassword = DLookup("[Password]", "tblDBUsers", "[ID] = " & varUserID )
    So that is...
    Code:
     
    string = dlookup ( string, table, [Long] long)
       1                 1              2       2
    ID is a field in a table set to autonumber which is defined as Lond Integer.
    Password is a field in a table set to text with [20] characters. It's also a Primary Key.

    So 1 and 1 matches, 2 and 2 matches. Please educate me, where is the mismatch please?
    Maybe that will do it.

  3. #3
    chuki2 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Location
    Selangor,Malaysia
    Posts
    26
    Hye there...i have one question about Dlookup....

    Sorry I did not want to open a new topic, so just want to share...hehe..

    How to read last record using dlookup?

  4. #4
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    The old read-the-last-record ploy...

    Are you really wanting to find the latest date? See the Max function. Count the records? See Count function.
    The last record, i.e. the one immediately end of file, in a table or recordset usually doesn't have special significance. If you really have to have the last record, Google "Access Movelast", which is a recordset method.

  5. #5
    graffiti is offline Newest Newbie ever
    Windows XP Access 2003
    Join Date
    Nov 2011
    Location
    Worthing, south coast of the UK
    Posts
    21
    To Hertfordkc.

    Apologies for the long delay in responding, I had to go out to an incident and have only just gotten back in to the office.

    Thanks very much for taking the time to post that. I knew it would be simple, but I was looking at the wring thing. It wasn't really a type mismatch, but the syntax of the type that was wrong.

    I have lots to learn. And then to try and remember! Books show so much but trying to find the correct syntax for the various ways of writing variables in a book isn't as easy as I would like.

    I'm sure I'll have other silly questions, but until then thanks again.

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. Error#13 Type Mismatch
    By Nistin27 in forum Access
    Replies: 8
    Last Post: 08-17-2011, 04:15 PM
  3. DLookup not recognizing valid record/type mismatch
    By walter189 in forum Programming
    Replies: 3
    Last Post: 07-21-2011, 07:03 AM
  4. type mismatch error?
    By hlcarlin in forum Programming
    Replies: 1
    Last Post: 07-07-2011, 08:30 AM
  5. Data type mismatch error
    By AccessUser123 in forum Queries
    Replies: 1
    Last Post: 05-22-2011, 07:48 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