Results 1 to 8 of 8
  1. #1
    Anil Bagga is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    69

    Red face Issue with DLookup : Errors

    I am fairly new to Access. I have 2 issues



    (1)

    I was creating a form wherein I need to capture values from a Table based on some key fields SONo (Text), ErpFGCode (Text), DiscountRate (calculated number)

    In the Form there is an unbound text box where I used the formula as below. SONo is a field in the Form (SOInvfrm) and also in the table CustSOTbl. Idea is to locate the MewarInvUnit in CustSOTbl where SONo captured in the SOInvfrm, matches with the SONo in the CustSOTbl

    =DLookUp([CustSOTbl]![MewarInvUnit],[CustSOTbl]![SONo]="& [SONo] "). I got an error #Name? in the form view. No compilation error. On checking different sites, I changed the formula as below

    =DLookUp([CustSOTbl]![MewarInvUnit],[CustSOTbl]![SONo]= '"&[SONo]&"'"). This gives a syntax error!!

    (2)
    In the same form I want to locate the DiscountRate from the table (this is a calculated field - Rate*Discount in the table). The SoNo is common for several items (ErpFGCode) in the CustSOTbl and each item has a different rate. Therefore I need I need to search for the rate based on concatenated string SONo+ErpFGCode. I tried several formulas but get a compilation error with all

    =DLookUp([CustSOTbl]![DiscountRate],"([CustSOTbl]![SONo])" & "([CustSOTbl]![ErpFGCode] )"= " & "[SONo] & [ItemCode]")

    =DLookUp([CustSOTbl]![DiscountRate],"([CustSOTbl]![SONo])" & "([CustSOTbl]![ErpFGCode] )"= " & "([SONo] & [ItemCode])")

    =DLookUp([CustSOTbl]![DiscountRate],"([CustSOTbl]![SONo])" & "([CustSOTbl]![ErpFGCode] )"= " & ("[SONo]" & "[ItemCode]"))

    I want to then eventually multiply quantity field of the form with the above rate fetched from the table

    =[QtySent]*[ItemRate]

    Please help a novice find his feet

  2. #2
    Anil Bagga is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    69
    I just tried this for case 1

    =DLookUp("MewarInvUnit","CustSOTbl","SONo=" & [SONo]). No syntax error but I get #Error in the Form view

    I checked and applied the Nz function as below to compensate if SO nos are not found in the table

    =DLookUp("MewarInvUnit","CustSOTbl","SONo=" & Nz([SONo],0)) but this gives a syntax error!

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    (1)Try:
    =DLookUp("[MewarInvUnit]","[CustSOTbl]"."[SONo]= '"&[SONo]&"'")

    If the tables are related, you should be able to add the "Lookup" field in the form Record Source query.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Anil Bagga is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    69
    =DLookUp([CustSOTbl]![MewarInvUnit],[CustSOTbl]![SONo]=[SONo]) gives an error &Name

    =DLookUp([CustSOTbl]![MewarInvUnit],[CustSOTbl]![SONo]=Nz([SONo],0)) gives a compilation error

    Surprisingly the expression below gives no error in another unbound text field

    =DLookUp("[DebtName]","[CustSOTbl]","[SONo] = " & Nz([Forms]![CustInvFrm]![SONo],0))

    I tried replacing this field name of DebtName with MewarInvUnit - circular reference error

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    (2)Try:
    =DLookUp("[DiscountRate]","[CustSOTbl]" & "[ErpFGCode]= '" & [SONo] & [ItemCode] & "'")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Anil Bagga is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    69
    The tables are linked on SO no

    I copy pasted the expression. =DLookUp("[MewarInvUnit]","[CustSOTbl]"."[SONo]= '"&[SONo]&"'")

    I get a compilation error. The . should be , possibly. On correction I get Circular ref error!

  7. #7
    Anil Bagga is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    69
    Bob,

    On (2) no compilation errors just that I get #Error due to SO no not found in the table

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I get a compilation error. The . should be , possibly. On correction I get Circular ref error!
    Yes, sorry. The full stop should be a comma.

    If the tables a related on the "SONo" field, then why not add the "CustSOTbl" table to the forms query which would enable you to have a text box bound to the "MewarInvUnit" field that you are trying to return with DLookup(). That would be the usual way
    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 issue
    By onlylonely in forum Programming
    Replies: 2
    Last Post: 03-13-2020, 02:39 AM
  2. DLookup and ELookup errors
    By MadTom in forum Forms
    Replies: 4
    Last Post: 09-06-2019, 12:50 PM
  3. Operator and Null errors with Dlookup
    By breezett93 in forum Access
    Replies: 14
    Last Post: 08-15-2017, 01:54 PM
  4. Replies: 3
    Last Post: 05-07-2013, 12:48 PM
  5. Dlookup issue
    By brharrii in forum Programming
    Replies: 3
    Last Post: 06-22-2012, 07:08 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