Results 1 to 6 of 6
  1. #1
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39

    Switch from using DLookup to using a Query to lookup customer info.

    There are 3 fields on my access 2007 form that are called "AdministeredBy", "PaymentBy" and "ShipTo". They are currently combo boxes where I select a customer number. Under each of these are several fields that use a DLookup function to bring up customer info from another table (First field looks up customer name, second looks up street address 1, third is street address 2, forth is city, then state, then zip).

    The dlookup will sometimes act up whenever I make any design changes to the form, such as moving, adding or deleting a button.



    I want to go from using the DLookup function to using a query to lookup the information, but I don't know how to start this.

    I'm still new to Access. Any help would be greatly appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Select * from tCustomer where [CustID] = " & forms!frmMain!cboCustID

    will pull the customer info based on the combo box.
    Save as a query and you can just open it or use it a a sub form too.

  3. #3
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    I paste that into each field?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by ranman256 View Post
    Select * from tCustomer where [CustID] = " & forms!frmMain!cboCustID

    will pull the customer info based on the combo box.
    Save as a query and you can just open it or use it a a sub form too.

    That is not the correct syntax it would be more like
    where (([tCustomer.CustID])=forms!frmMain.cboCustID)

  5. #5
    dmon2010 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2013
    Posts
    39
    (([tCustomer.CustID])=forms!frmMain.cboCustID)

    So I would change:

    Customer = the name of my customers table
    frmMain = The name of my form (or do I leave the 'frm')
    CustID = the name of each combo box (AdminBy, PayBy or ShipTo)

    Is that correct?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by dmon2010 View Post
    Is that correct?
    Sounds about right. The easiest approach to create a parameterized query is to type directly into the grid located towards the bottom of the Query Builder while in Design View. So, in the Criteria field

    Forms!
    then hit tab
    Select the form name and hit tab

    then type the name of the control you are after.

    The result will be a WHERE clause similar to what has been posted here. One word of advise, you want to test for null or empty strings incase your combo's do not have anything in them, like when the form opens. I don't normally build Dynamic Parameterized Queries but my preference is an Instant If function to test for Null.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-06-2013, 11:37 PM
  2. DLookup Customer Ship method
    By burrina in forum Forms
    Replies: 2
    Last Post: 12-17-2012, 09:20 AM
  3. Need some DLookup Help For Customer
    By burrina in forum Forms
    Replies: 3
    Last Post: 11-18-2012, 04:32 PM
  4. Replies: 2
    Last Post: 09-11-2012, 07:54 AM
  5. Lookup vendor amounts per customer
    By btr94 in forum Access
    Replies: 9
    Last Post: 07-06-2012, 10:44 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