Results 1 to 3 of 3
  1. #1
    ijo68 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2021
    Posts
    37

    Using Dlookup to get value from a Query

    Hello All,



    I do not understand why this does not work. I'm trying to get the email address from this query (PubFlNm). but can't figure out why it doesn't work. I would appreciate any help I can get .. Thank you Kindly in advance.

    VBA code ..Dim Em as String

    Em = DLookup("email", "PubFlNm", "FLname = ' " & Me.GrpOS.Value & "'")

    Click image for larger version. 

Name:	PubQ.jpg 
Views:	16 
Size:	63.1 KB 
ID:	44565

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Perhaps:
    Em = DLookup("email", "PubFlNm", "FLname = ' " & Me.GrpOS & "'")

    Also, perhaps you could add the query to the forms Record Source rather than using DLookup()

    IMHO whatever you do it would be easier if you had an Auto-Number Primary Key in every table
    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
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    "Doesn't work" doesn't help much as I always say. If you were to say "I get a number instead of a name" then we'd ask if GrpOS is a combo box, in which case you're likely passing the bound (ID) field to the expression and not the name you see in the combo. Then again, you would have to have said that you're stepping through the code (a very basic trouble shooting procedure) to even know that you're passing a number as criteria to DLookup. Less powerful but still helpful is a message box to tell you what's in the control before you try to use it.

    To me, the most intriguing thing is, IF the control on the form is a combo and FLname and Email are in the same table, then why not just add Email as a column to the combo?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Using DLookup with NZ in query.
    By JRodko in forum Queries
    Replies: 6
    Last Post: 01-28-2019, 02:25 PM
  2. Replies: 4
    Last Post: 02-13-2016, 06:00 PM
  3. dlookup on query
    By molly13 in forum Access
    Replies: 3
    Last Post: 10-21-2014, 09:00 AM
  4. Dlookup in query
    By Bertrand82 in forum Queries
    Replies: 9
    Last Post: 11-14-2012, 06:42 AM
  5. Query with Dlookup
    By mari_hitz in forum Queries
    Replies: 5
    Last Post: 10-14-2011, 09:22 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