Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2010
    Posts
    26

    Noob question - Query that restricts to selection of other attribute

    I dont know how to phrase this in technical terms, so it is difficult for me to check online the solution to this.



    My Query is for contacts. When the users will enter a new contact, the two first fields are the Company and the address. There will be hundreds of contacts once this tool is in production, and 1-8 addresses per company. Therefore I need to make it so that when the user selects the proper company, the next field restricts itself to what the user inputted.

    How do I set this up?

    Currently I only have a selection box, but it is unrestricted, and therefore shows everything in the vendor table.

    Thanks for any help

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You are describing cascading combo boxes. For the cascading combo boxes to work, you will need the correct table structure. You say that a company can have many locations. So a basic structure would look like this

    tblCompanies
    -pkCompanyID primary key, autonumber
    -txtCompanyName

    tblCompanyLocations
    -pkCoLocationID primary key, autonumber
    -fKCompanyID foreign key to tblCompanies
    -txtAddress
    -txtCity
    etc.

    Bob Larson's site has an example database that illustrates cascading combo boxes. Roger Carlson's site also has examples

  3. #3
    Join Date
    Jul 2010
    Posts
    26

    Thanks!

    Thanks Jwzp11,

    My desing corresponds to what you suggested me to do. Thanks for directing me to the right tutorials!!!

  4. #4
    Join Date
    Jul 2010
    Posts
    26
    Ok, I corrected the query so that it restricts to the current form like this:

    SELECT tblAddresses.pkAddressID, tblAddresses.fkVendorID, tblAddresses.txtAdressNoAndStreet, tblAddresses.txtCity, tblAddresses.txtProvince_State, tblAddresses.txtCountry, tblAddresses.txtPostal_Zip_Code FROM tblAddresses WHERE (((tblAddresses.fkVendorID) Like [Forms]![frmContacts]![fkVendorID]));


    My table structure is:

    Vendor Table:
    pkVendorID
    txtVendorName
    txtConsortiumID
    txtParentID


    Contact Table
    pkContactID
    fkVendorID
    txtMailStop
    txtLastName
    txtFirstName


    and my form named frmContacts contains everything in the contact table



    It does not update.... How come? Is there an additional step I have to take other than changing the query? Thanks.

    EDIT: I figured it out. So for the sake of completing my question:

    Add VB code to the first combo box... properities -->event --> afterupdate add VB code that executes the query of the second combo box like so:

    Private Sub fkVendorID_AfterUpdate()
    On Error Resume Next
    Me!fkVendorID = "SELECT tblAddresses.pkAddressID, tblAddresses.fkVendorID, tblAddresses.txtAdressNoAndStreet, tblAddresses.txtCity, tblAddresses.txtProvince_State, tblAddresses.txtCountry, tblAddresses.txtPostal_Zip_Code FROM tblAddresses WHERE (((tblAddresses.fkVendorID) Like [Forms]![frmContacts]![fkVendorID]));"

    End Sub


    And everything works like magic.
    Last edited by Alexandre Cote; 07-20-2010 at 09:36 AM. Reason: figured it out

  5. #5
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Regarding your query, it would be better to use = instead of Like in the criteria since you are looking for an exact match. Also, since you are assigning the query to the row source in code, you have to have the vendorID as a variable not as part of the SQL text. You can also use the "me." short hand to refer to the form since you are executing the code from the same form.

    Code:
     
    Me.Combo39.RowSource ="SELECT tblAddresses.pkAddressID, tblAddresses.fkVendorID, tblAddresses.txtAdressNoAndStreet, tblAddresses.txtCity, tblAddresses.txtProvince_State, tblAddresses.txtCountry, tblAddresses.txtPostal_Zip_Code FROM tblAddresses WHERE (((tblAddresses.fkVendorID) ="  & me.combovendor

  6. #6
    Join Date
    Jul 2010
    Posts
    26
    Yeah i was pretty buggy indeed lol that seems to have fixed the problem

  7. #7
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Great! Let us know if you have any other questions.

  8. #8
    Join Date
    Jul 2010
    Posts
    26
    Thanks a lot for you help, this forum is really helping me a lot! I am an IT intern in a departement in which there is not an appropriate mentor. It is relieving a lot of stress.

  9. #9
    Join Date
    Jul 2010
    Posts
    26

    I changed the code a bit

    Finally I changed the code and decided to let the object handle the requiry. I did so by giving this code:

    Me.Combo39.Requiry

    I also did the changes you said for the "Like"

    Everything seems to be perfect now :-) Thanks a lot!

  10. #10
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome. Glad you got it worked out.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-05-2010, 04:31 PM
  2. Unnhide Attribute?
    By thorsonb in forum Access
    Replies: 1
    Last Post: 03-30-2010, 10:21 PM
  3. HELP NOOB! Easy question
    By SigmaBlu in forum Queries
    Replies: 1
    Last Post: 10-10-2009, 11:23 AM
  4. Replies: 2
    Last Post: 05-27-2009, 08:47 PM
  5. Noob Query Help Needed
    By fenster89411 in forum Queries
    Replies: 0
    Last Post: 01-11-2009, 09:47 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