Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    DLookup not working

    The db file that I have attached to this post has a form called frmemail. In it I am trying to match an email with a person's name. I am using the DLookup function as the control source for that box.

    It is not working and I am not sure why. I put the DLookup as the control source, but when I run it - no luck.

    What am I doing wrong?

    Any help appreciated. thanks in advance.



    Respectfully,

    Lou Reed
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    put the names and emails in a query.
    the query will pull: name, email
    put this query in a list box w 2 columns,(lstEmail), then bind the listbox to the email.
    select item in list, THIS is the email that will be sent. No Dlookups.

    docmd.SendObject acSendReport ,"rptName",acFormatPDF,lstEmail,,,sSubj,sMsg,fa lse

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    What you say would probably work. But what is wrong with what I already have done here. It seems that DLookup should work.

    I will try what you said, but what is wrong with what I already have. I just want to know.

    Thanks in advance.

    Respectfully,

    Lou Reed

  4. #4
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I am not understanding the following sentence in your post.

    Code:
    put this query in a list box w 2 columns,(lstEmail), then bind the listbox to the email.
    Especially, the last part "then bind the listbox to the email".

    Please explain. I know it may be obvious to someone who has worked a lot with this. It is just not obvious to me.

    Thanks in advance.

    Respectfully,

    Lou Reed

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    ThE listbox already has the data. There no need to do more lookups.
    (sorry if my wording was unclear)

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    1. I guess that I am not understanding the last two instructions or steps in your explanation. The last part of this is what I do not understand.


    "put this query in a list box w 2 columns,(lstEmail), then bind the listbox to the email."

    I did create a listbox with the listbox wizard. I did put the email address first. Then bind the listbox to the email? I am not sure how to do that.

    Also

    2. I do not work with listboxes very often if at all. There are two columns in the listbox with the first the email address and the second the employee's name associated
    with the listbox.

    The db user should select the employee's name from the listbox and the email address for that employee is shown, then the email is used when to message is sent in the to column.


    The user select employee's name and the email is selected from that. The email and the employee are in the same table.

    Since this table is the record source for the form, why not just use email direct as a control source for the no listbox or DLookup?

    Once you have the table as the record source, it seems that you can choose any field off of it as a control source for the textbox. I chose email.

    Again eliminating listboxes and DLookups or anything else. As I said the employee name and the email are in the same table!

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your DLookup fails because you need to refer to the combo, since the field isn't on the form. You also spelled the key field wrong. It works with:

    =DLookUp("[email address]","tblPersonnel","PersonnelID=" & [Combo42])

    I'd just use your existing combo and add the email field to it:

    BaldyWeb - Autofill
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, and I had to add brackets due to the inadvisable space in the field name.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    What is Combo42? I assume it is the combo box with the email address and full name. Thus is should be a two column combo email first then full name.

    As far as the email address. I am unsure as to when I can use a space or not. A space adds readability and leaving one out eliminates the above error.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Combo42 is the name of the combo for Employee Name on frmEmail. It's a 2 column combo with PersonnelID and FullName.

    You "can" use one any time. You "shouldn't" use one ever in an object name. I use camel case: EmailAddress. Others use underscores: Email_address. Again, you "can" use them, but it will cause you headaches like this.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    One other question, what if name and email address are on the same table, then you should not need to use DLookup to find the email address once you have the full name.

    It seems we are looking for an association between name and email address. If name and email address are on the same table then that association already exists.

    Thus no DLookup is required.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  12. #12
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No, you don't need DLookup(). I'd just add it to that combo, ranman mentioned a listbox, same solution. Then you simply get it like I showed in the link, using the Column property of the combo/listbox.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    So you only use DLookup when you are getting the email address that is not on the same table as the name?

    Is this correct?

    Thanks in advance.

    Respectfully,

    Lou Reed

  14. #14
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    This attachment works sort of

    Okay, in this example which I have attached. I can select the names on the frmpersonnel and it shows the names in frmemail. However,
    the email section shown right below names in forms email shows the employee ID not the employee email address.

    What is going on here?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, not to sound trite, but you use DLookup() when it's the appropriate tool for the job. I wouldn't say it's a hard and fast rule that you'd only use it when it's in a different table. If for whatever reason I only had the user name and needed the email, I might use a DLookup(). It wouldn't really matter what the table structure was at that point, just "okay, here's what I have, here's what I need, what's the best way to get it?". I might just be able to add the field to a form. I might use a recordset because I need more than one field.

    I can tell over time that you've been working really hard to learn Access, and I applaud that. I think it's less a matter of learning a rigid set of rules as it is learning what the available tools are, what their advantages and disadvantages are, so you can then apply that knowledge to make decisions in individual situations, because each situation is unique (how's that for a run-on sentence!). I've been at it a long time, and I still learn new ways of doing things.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dlookup not working
    By shaunacol in forum Forms
    Replies: 8
    Last Post: 06-12-2015, 09:28 AM
  2. Three criteria in Dlookup not working?
    By dcdimon in forum Programming
    Replies: 5
    Last Post: 07-03-2014, 07:04 AM
  3. Autofill using DLookup not working
    By BBonexx in forum Access
    Replies: 2
    Last Post: 01-08-2013, 09:18 PM
  4. DLookup isn't working
    By cec in forum Access
    Replies: 7
    Last Post: 12-28-2012, 12:21 PM
  5. DLookup code not working
    By lukekelly in forum Programming
    Replies: 9
    Last Post: 06-15-2010, 06:08 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