Results 1 to 6 of 6

Thread: ado and cbo boxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    7

    ado and cbo boxes

    I have two table in access with the following fields:
    HotelID and Location in table hotel and
    HotelID and UserName in table user.
    When I populate a cbouser with the username I need to populate cbolocation with the location. The table are related through Hotel.HotelID and user.HotelID. As I select a username in cboUser I need to see the related record in cbolocation.
    Does anyone have any suggestions as to how to do this?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    SELECT U.HotelId, U.UserName, H.Location FROM User U LEFT JOIN Hotel H ON U.HotelID = H.HotelId

  3. #3
    Hyperactive Member dRAMmer's Avatar
    Join Date
    Oct 2001
    Location
    strangelans
    Posts
    463
    What do you mean by related information. Does one username can have different location? If so then
    VB Code:
    1. private sub cboUser_Click()
    2. 'by mendhak
    3. rs.open "SELECT U.HotelId, U.UserName, H.Location FROM User U LEFT JOIN Hotel H ON U.HotelID = H.HotelId WHERE U.Username ='" & cboUser.Text & "'",YourCN, adOpenStatic, adLockReadOnly
    4. if not (rs.bof and rs.eof) then
    5.    'populate your cboLocation
    6. end if
    also it's better if the where cluase will be by code, say UserID, like so:
    VB Code:
    1. private sub cboUser_Click()
    2. 'by mendhak
    3. rs.open "SELECT U.HotelId, U.UserName, H.Location FROM User U LEFT JOIN Hotel H ON U.HotelID = H.HotelId WHERE U.ID =" & cboUser.ItemDate(cbouser.listindex)",YourCN, adOpenStatic, adLockReadOnly
    4. if not (rs.bof and rs.eof) then
    5.    'populate your cboLocation
    6. end if
    live, code and die...

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    7

    ado and cboboxes

    Each user can have only one location.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Use drammer's code with my SQL query instead. You can change the other combobox's item in the first combo's change event.

  6. #6
    Hyperactive Member dRAMmer's Avatar
    Join Date
    Oct 2001
    Location
    strangelans
    Posts
    463

    Re: ado and cbo boxes

    Originally posted by skicrud
    When I populate a cbouser with the username I need to populate cbolocation with the location. As I select a username in cboUser I need to see the related record in cbolocation.

    Each user can have only one location.
    Why do you need to populate a combo box then? If only one location can be designated to one user then why not use a textbox instead?
    live, code and die...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width