|
-
Nov 9th, 2004, 09:39 PM
#1
Thread Starter
New Member
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?
-
Nov 10th, 2004, 12:06 AM
#2
SELECT U.HotelId, U.UserName, H.Location FROM User U LEFT JOIN Hotel H ON U.HotelID = H.HotelId
-
Nov 10th, 2004, 12:15 AM
#3
Hyperactive Member
What do you mean by related information. Does one username can have different location? If so then
VB Code:
private sub cboUser_Click()
'by mendhak
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
if not (rs.bof and rs.eof) then
'populate your cboLocation
end if
also it's better if the where cluase will be by code, say UserID, like so:
VB Code:
private sub cboUser_Click()
'by mendhak
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
if not (rs.bof and rs.eof) then
'populate your cboLocation
end if
-
Nov 10th, 2004, 06:32 AM
#4
Thread Starter
New Member
ado and cboboxes
Each user can have only one location.
-
Nov 10th, 2004, 07:27 AM
#5
Use drammer's code with my SQL query instead. You can change the other combobox's item in the first combo's change event.
-
Nov 10th, 2004, 07:27 PM
#6
Hyperactive Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|