Results 1 to 14 of 14
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    DLookUp Statement Help


    Code:
      CboContactPhoneType = DLookup("ContactPhoneID", "ContactPhoneByLocationQry", "CompanyLocationID=" & [CboLocationID] & "  AND Preferred=True"
    I need to add to the above statement "CompanyContactID=" & [TxtCompanyContactID] & " and I cant figure it out?
    Thanks

  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,544
    What data type are fields "CompanyLocationID" and "Preferred" in the 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
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    This is used on the OnCurrent of form. CompanyLocationID is a # and Perferred is a chkBox.
    What this does is limit the current phone numbers to a single company by the LocationID. I want to add so that it also limits to the CompanyContactID also.
    Example:\
    Company can have multi locations, and Locations can have multi Contacts so i want to limit my phone numbers to the company location and by the company contact.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    CboContactPhoneType = DLookup("ContactPhoneID", "ContactPhoneByLocationQry", "CompanyLocationID=" & [CboLocationID] & " AND [Preferred]= -1")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi, I dont think you understood or i didnt make myself clear enough. The origional code works well, i just need to add a second part to it "CompanyContactID=" & [TxtCompanyContactID] & " along with the other code
    I just dont know how to nest this in a statement.

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    CboContactPhoneType = DLookup("ContactPhoneID", "ContactPhoneByLocationQry", "CompanyContactID=" & [TxtCompanyContactID] & " AND CompanyLocationID=" & [CboLocationID] & " AND Preferred=True"
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I get a syntax error on open
    Compile error

  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,544
    What do you get if you open the forms code module and type:

    ? DLookup("ContactPhoneID", "ContactPhoneByLocationQry", "CompanyContactID=" & [TxtCompanyContactID] & " AND CompanyLocationID=" & [CboLocationID] & " AND Preferred=True"

    in the immediate window (followed by "Return" key of course
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Expected list separator or )
    Compile Error

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by d9pierce1 View Post
    Expected list separator or )
    Compile Error
    Sorry. Try

    ? DLookup("ContactPhoneID", "ContactPhoneByLocationQry", "CompanyContactID=" & [TxtCompanyContactID] & " AND CompanyLocationID=" & [CboLocationID] & " AND Preferred=True")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    External name not defined

  12. #12
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I also tried the one i am currently using and it says the same thing but it works for setting the form on current. Not sure what is going on here.

    What i am doing with this is a combo on my company contacts form. I want that combo only to show my phone numbers for that contact by that location.
    Example:
    Company = Parkway
    Location = Corporate Office
    Contact - David Pierce
    Below should be in combo
    Phone Line Moile Type 2145429664
    Phone Line Office Type 7690337878

    Contact = Rob Sanders
    Below should be in combo
    Phone Office Direct Line Type 9198989999
    and so on...

    When my contact form opens it opens up to the correct location.

    I must need to do some testing and such.

    Maybe a where clause in the combo?

    Thanks

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Maybe a where clause in the combo?
    I think so
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I fixed it, just stupid me.... One day i am going to get this correct! ONE DAY
    Thanks
    Dave

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

Similar Threads

  1. Building a DLookup statement correctly
    By Lou_Reed in forum Access
    Replies: 4
    Last Post: 04-03-2017, 07:45 AM
  2. Replies: 1
    Last Post: 04-27-2015, 08:31 AM
  3. Dlookup with a function in the where statement
    By nigelbloomy in forum Queries
    Replies: 3
    Last Post: 07-31-2013, 10:07 AM
  4. using the and function in a dlookup statement
    By englisap in forum Programming
    Replies: 10
    Last Post: 01-10-2011, 09:53 PM
  5. Help Using Variable in DLookup Statement
    By bcmarshall in forum Access
    Replies: 9
    Last Post: 12-02-2010, 12: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