Results 1 to 5 of 5
  1. #1
    smeghead67 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    31

    DLookup with textfield in criteria

    Hello,



    I am creating a form that looks up the value of a field on a table that matches two criteria on my form.

    My table [partstore] has three fields, [binid], [pid] and [qty] their values are L01-01-03, 2 and 3

    my form [takeapart] (For this question) has two text boxes [psid] and [pid]. the values entered into the forms are L01-01-03 and 2

    I'm trying the following code in a button,
    Code:
    Dim getbqty As Integer
    getbqty = DLookup("[qty]", "[partstore]", "[pid]=[Forms]![takeapart]![pid] AND [binid]='" & [Forms]![takeapart]![psid] & "''")
    MsgBox getbqty
    When I run this I get "Invalid use of Null"

    When I go to immediate mode to debug it, running the dlookup with just the pid = forms pid works but trying the binid to psid comparison always results in a null?

    What am i doing wrong?

    Ted
    Last edited by smeghead67; 08-07-2012 at 10:25 AM. Reason: Solved

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    If binid is text try:
    Code:
    Dim getbqty As Integer
    getbqty = DLookup("[qty]", "[partstore]", "[pid]=" & [Forms]![takeapart]![pid] & " AND [binid]='" & [Forms]![takeapart]![psid] & "'")
    MsgBox getbqty
    If binid is numeric try::
    Code:
    Dim getbqty As Integer
    getbqty = DLookup("[qty]", "[partstore]", "[pid]=" & [Forms]![takeapart]![pid] & " AND [binid]=" & [Forms]![takeapart]![psid])
    MsgBox getbqty
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    smeghead67 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    31
    Bob,

    binid is text. your sample code only changed how it handled the [pid] which is numeric. the way it handled the binid was the same as what i already had. when i check this in immediate mode,

    Code:
    ? DLookup("[qty]", "[partstore]", "[pid]= [Forms]![takeapart]![pid]")
    will return the first record where the criteria is true. but,

    Code:
    ? DLookup("[qty]", "[partstore]", "[binid]='" & [Forms]![takeapart]![psid] & "'")
    always returns a null, even though i have copied the values from the table to the form so I know it is there.

    odd isn't it?

    Ted

  4. #4
    smeghead67 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    31

    Lightbulb Eurika! I have found it (or am I repeating myself?)

    I believe i have found my problem.

    I just tried the following code,
    Code:
    ? DLookup("[binid]", "[partstore]")
    It returned "L010001"

    Wait, that's not the format its saved in... OH

    I remembered when i created the table "partstore" i put an Input Mask of !LAA\-00\-00 on the field "binid". I thought it stored the info with the dashes in it because when you look at the table, in datasheet view, the first value of [binid] is L01-00-01.

    So, all I had to do was put that input mask on the binid text box of my form and BINGO! it works. Thank you, Bob for helping with an "Idiot Coder Error"

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Glad that I have been of some help. Thanks for posting back with the full solution.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Dlookup with multi Criteria
    By rkalapura in forum Forms
    Replies: 2
    Last Post: 06-15-2012, 06:18 PM
  2. dlookup with a contains criteria?
    By noretoc in forum Access
    Replies: 3
    Last Post: 05-02-2012, 10:18 AM
  3. DLOOKUP criteria using variable
    By Thumbs in forum Programming
    Replies: 14
    Last Post: 02-21-2012, 08:08 AM
  4. DLOOKUP where TEXTFIELD > SEARCHSTRING
    By Whizbang in forum Access
    Replies: 1
    Last Post: 12-20-2011, 01:48 PM
  5. Multiple criteria in DLookup
    By crowegreg in forum Forms
    Replies: 7
    Last Post: 06-22-2011, 01:47 AM

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