user generated primary keys
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Access Training and help » User generated primary keys

User generated primary keys

resolvedResolved · Urgent Priority · Version 2003

replyReply Fri 2 Jul 2010, 15:54Delegate Pasquale said...

Pasquale has attended:
Access Introduction course
Access Intermediate course
Access Advanced course

User generated primary keys

Hello,

I have a database with several tables including contactinfo, cases, risk and others. Each family has several fields entered in each table and they are all have relationships. The primary key generated for the contactinfo table is a combination of the following:

the first three letters of a family name
the first letter and number of the postcode
the last three letters/numbers of the postcode

e.g. Jones living in SW1 ER6 would have a primary key JONSWER6

That would also be the primary key for the risk and cases table.

How can I develop a macro/vba so that the person entering the address and fmaily name information doesn't have to do it manually, and for the primary key to populate other tables like cases, risk and other tables.

Thanks

For upcoming training course dates see: Pricing & availability

replyReply Thu 8 Jul 2010, 17:35Trainer Anthony said...

RE: User generated primary keys

Hi Pasquale, thanks for your query.

Your query raises several issues. First of all, it is bad practice to create a primary key in the manner you're suggesting. Ideally, you should create a composite primary key by indicating the fields on the table which, when combined, create unique identifiers for each record. What you're doing is creating what is technically know as "derivative data" which can reflect upstream errors and therefore affect the functioning of the database.

If you attempted to create a primary key in the manner you suggest, you would need to parse the data (chop up the postcode by looping through it and cutting it when it sees a space), then concatenating it with only the first three letters of the family name (again by looping through each value) and bolting all that together with the remains of the postcode. While this is possible on a datasheet, it would make more sense to collect the information via a VBA user form, combine it and then populate the relevant fields on the series of tables in your database. As you can probably understand, a close description of how to do this is beyond the scope of this forum, so if you would like to pursue this with a trainer please do contact us via the telephone number of the website. We'd be only too happy to help you build the tool you need.

All the best,

Anthony

 

Please browse our web site to find out more about
access courses and other Microsoft training courses.

Access tip:

Random sampling

Data is th key to a good database, therefore checking is essential.

A good way of checking data is by random sampling. You can do this in a query, by typing the follow:
1) In the Field box create a RandonID field eg. Randon Id: Rnd(fieldname])

2) sort the field
3)Right click and chage the properties for To value to be the number of randon records you want to see.

4) Change the set to Show row for Randon ID to be False, add all the other fields you want to see and the run the query.

View all Access hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard