Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2006, 05:49 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Field/Key Concatenation

Hello,

Im requiring help on an database i am trying to create. I am making a database on universities in the area and the courses they offer.

Heres my problem, id like to make a primary key for a course offered(for example) 123456. Id like this primary key to be a concatenation for the information of the course. For example: 123456 would give the information for that course. So, '12' would be the university code (which would give the university name, eg, '12' = University of Sydney), '34' would be the faculty code (which would give the faculty name, eg, '34' = Business) and '56' would be the course code (which would give the course name, eg, '56' = Bachelor in Economics).

I would like the '123456' to be the unique course code, which in itself would give its own information.

Im not sure if im being clear in my problem and what i would like, if you have questions, be sure to ask.

Thank you in advance.
Patricio
 
Old May 15th, 2006, 08:30 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can do this very simply, but I would not make it the real Primary Key, since it is easy to see there will be duplicates.

Make an autonumber field and keep it hidden and use it as the real PK for the record.

Then pull the data for the fields you want to concatenate for you course identifier. Then make this number when you need to display it in a form or report (using a query) like this:

CourseNo.:([UnivCode] & [FacultyCode] & [CourseCode])

The problem is since these are numbers, the concatenation may give you this answer instead of "123456": 12 + 34 + 56 = "102". Therefore, even though you are using numbers, make this a text field since you are never going to do arithmetic with the numbers.

If you create a table for each of these entities, like:

tblUniversity
UnivID - PK (autonumber)
UnivCode - text
UnivName - etc

Then in your combo boxes you can pull the ID, code and name, and display the name, and still have the code to do your on form display of your compound number if you want.

Does this help?


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to drop a field with primary key jeffcflam Pro VB Databases 1 May 4th, 2006 01:51 PM
Can i use text type field in Access as primery key geetageetageeta ASP.NET 2.0 Basics 1 March 4th, 2006 09:31 AM
unique primary key field in CR kelvinklein82 BOOK: Professional Crystal Reports for VS.NET 0 December 29th, 2004 11:52 AM
How Do I Concatinate fields into a key field Brian263 Access 1 May 3rd, 2004 03:00 PM
When more than one field in a primery key - DGrid ManoYaka ASP.NET 1.0 and 1.1 Basics 3 January 21st, 2004 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.