comments inline.
bw said:
Before getting into the Combo boxes, here are the details for my tables.
tblHotels
Primary Key: HotelID, Indexed, Yes (No Duplicates), Data Type: AutoNumber
Field Name: txtHotel, Indexed, Yes (Duplicates Ok), Data Type: Text
if i were going to index field txtHotel, i'd set it to No Duplicates. this
table is simply a listing of all hotels. you don't want or need the exact
same hotel name listed twice.
tblLocations
Primary Key: LocationID, Indexed, Yes (No Duplicates), Data Type: AutoNumber
Field Name: txtLocation, Indexed, Yes (Duplicates Ok), Data Type: Text
if i were going to index field txtLocation, i'd set it to No Duplicates.
this table is simply a listing of all locations. you don't want or need the
exact same location listed twice.
tblHotelLocations
Primary Key: HLID, Indexed, Yes (No Duplicates), Data Type: AutoNumber
Field Name: HotelID, Indexed, Yes (No Duplicates), Data Type: Number
if you're going to index field HotelID, set it to Duplicates OK. remember,
one hotel may have many locations, so you need to be able to list the same
HotelID many times.
Field Name: LocationID, Indexed, Yes (No Duplicates), Data Type: Number
In the indexes box,
if you're going to index field LocationID, set it to Duplicates OK.
remember, one location may have many hotels, so you need to be able to list
the same LocationID many times.
Index Name1 is Primary Key, Field Name is HLID , and Index Properties:
Primary=Yes, Unique = Yes
Index Name2 is Tina, Field Name is HotelID, and Index Properties: Primary
=No, Unique = Yes
Index Name 3 is empty, Field Name is LocationID, and Index Properties are
not available
your two-field index is set up correctly (though i'd have picked another
index name <g>). with the changes on the individual field index settings
noted above, the table will accept the same HotelID multiple times, and the
same LocationID multiple times, but each *combination* of HotelID and
LocationID must be unique.
Relationships
tblHotels>HotelID is one-to-many related to tblHotelsLocations>HotelID
tblHotels>LocationID is one-to-many related to tblHotelsLocations>LocationID
MainForm=frmHotels
SubForm=frmLocationsSubForm1
Link Master Fields=HotelID
Link Child Fields = LocationID
it's not clear what tables are bound to the forms. i assume that tblHotels
is the RecordSource of frmHotels. but what table is used as the RecordSource
of frmLocationsSubForm1?
standard setup would be:
frmHotels.RecordSource = tblHotels
frmLocationsSubForm1.RecordSource = tblHotelLocations
the subform has combo box in it, with the ControlSource set to the
LocationID field in tblHotelLocations. the RowSource of the combo box is
tblLocations.
result: in the main form, you move to a specific hotel record. in the
subform, you add a record for every location that hotel is found at, using
the combo box "droplist" to choose each location from tblLocations.
obviously, you can add new hotel records directly in the main form. to add a
location to tblLocations during data entry in the subform, you can add code
to the combo box's NotInList event to update the locations table and the
combo box list - it's a commonly used process.
hth