Primary Key with Embedded Counter

G

Guest

I have a database that tracks data about inspections of apartment units. I
have a table called tblUnit_Detail with a autonumber PK = Unit_ID. I have a
related table called tblBedroom_Detail. I want the PK in this table to be
made up of the appropriate Unit_ID and which bedroom we are looking at.

So if Unit_ID 22 has 4 bedrooms, I want to put in 4 records with primary
keys of Bedroom_ID = 22-1, 22-2, 22-3, 22-4.

How would I link the tables and how do I put a counter in the PK?
 
G

Guest

Have your tblBedroom_Detail to have a field for Unit_ID and another for the
counter withit. Use form/subform linked on your Unit_ID field. Use
double-click in subform field to check records matching Unit_ID, increment,
and insert new record.
 
G

Guest

Thanks for your quick response. I have a few questions. When you say put a
second field in the tblBedroom_Detail for the counter - are you talking about
an autonumber? If so, once I have input 40 units that have 3 bedrooms each,
won't my bedroom autonumber be showing up as 121? Is there a way to have the
unique ID in the bedroom table be 1 (for the UnitID) and 1,2 or 3 for the 3
bedrooms in UnitID 1?

When you say "double-click in subform field to check records matching
Unit_ID, increment, and insert new record" can you talk a little more about
what you mean by double click in subform field?

Thanks
 
G

Guest

When you say put a second field in the tblBedroom_Detail for the counter -
are you talking about an autonumber?
No. It will be a text field that is updated using the number in the Unit_ID
field and your 'counter'.
Open the subform in design view, click on the Unit_ID, right-click and
select Properties. Scroll down properties to the one labeled 'Double Click'
and build an expression or call a macro to increment your count, and insert
new record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top