Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
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 February 4th, 2006, 07:42 PM
Registered User
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy auto number value to another form

I have an entry form that uses a auto number field to assign job numbers. There is a command button on the form to open another form. The forms are linked via the auto number field from the first form. I cannot get the auto number value from the first form to automatically be copied to the second form. Any thoughts on how to do this? I have tried a 'setvalue' marco, without any luck.

 
Old February 6th, 2006, 09:01 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Just create a new field in the linked table and make the autonumber field on the other table its look up. You may have to modify the query if you are using the look up wizard and the autonumber field is not the PK of the other table. But anyway, if they are linked, it will automatically populate the linked table when a new record is created.

mmcdonal
 
Old February 6th, 2006, 12:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

To answer the question, you can put something like this on the second form when a new record is added (I'm using fake names):

Me.txtRecNo = Forms.OtherForm.Form.txtRecNo

But to caution you, you said, "I have an entry form that uses a auto number field to assign job numbers." You should NOT be doing that. Autonumbers have no meaning whatsoever except to relate data from one table to another as you're doing in your forms. If you want to crate a meaningful Job Number that people will actually see (NEVER show autonumbered fields to the users), you should put that its own field.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old February 6th, 2006, 12:26 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can use autonumber fields to create job numbers as you are doing, just don't make the job numbers the clustered index or Primary Key of the table. That can (and should) also be an autonumber field, but never shown to the user.

mmcdonal
 
Old February 7th, 2006, 10:11 PM
Registered User
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mmcdonal & SerranoG

Thank you both for the information. I have found a solution to my question, since the post.

I do have another question. Both of you mentioned not using the primary key and/or an autonumber as the job number. Why? What are the pitfalls? This is my first dataBase to design. I have not implemented it yet. I plan to do so within the next couple of weeks. If there is something that I am missing I would like to know it now.

I look forward to your replies.

 
Old February 8th, 2006, 09:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Autonumbered fields are used to uniquely identify a record in a table. Each table will have this field as a primary key. Subordinate tables will have a foreign key set to a long integer to match the value of the main table's autonumber. The foreign key will usually get assigned automatically via a parent/child relationship in a form & subform.

The sole purpose of these numbers is to keep track of related records throughout the database. These numbers are never seen by any user. They are used in the background by the computer in queries, SQL statements, and VBA code. Their actual values are meaningless and it doesn't matter if they're sequential or not, just as long as they're unique.

If you want to use meaningful ID numbers for something that users will see and use, you create your own field (not an autonumber) that has a format that makes sense to you. These fields usually DO matter if they're sequential or make some kind of sense to the user. These are seen and refered to by users in forms and reports.

The pitfalls of using autonumbers to actually have meaning is that these numbers usually have to be sequential to users. If you delete any records, Access does NOT renumber anything. You will have gaps in your numbering. If someone starts a record and then deletes it and then puts it back, the autonumber will not come back and be repeated; Access will choose the next autonumber. To Access, the number is not intended for "meaningful" use so it just assigns numbers... period.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old February 9th, 2006, 07:54 AM
Registered User
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SerranoG

Thanks for the input. Let me explain what I'm doing in more detail. We perform annual calibrations on equipment we sell. When we receive an item for calibration, we assign it a 'Job #'. This number is unique & sequential. It follows the item while it is in-house, until it ships. In fact it becomes our calibration number that is listed on the calibration certificate. The system currently in place, for assigning 'Job #' & tracking the item in-house, is a manual, paper system. We use a log book to assign a unique & sequential 'Job #' when the item is received. I am moving our paper system to a database system, having a unique 'Job #' is critical. Using the autonumber appears to be the most simple way to handle this.

Is there another reason why I should not use the primary key from my receive table as the 'Job#'?

Thanks again for any help.



 
Old February 9th, 2006, 09:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Is there another reason why I should not use the primary key from my receive table as the 'Job#'?
Yes, you said that job no. has to be sequential. If you delete a job or accidentally delete it and put it back manually, you WILL lose your sequential number. You will NOT be able to set the next number as one plus the previous.

The only way to renumber the autonumber field is to compact and repair the database, open a new copy of your table and data dump all your data into a new table and erase the old one. That would be a BAD idea because then you will lose your previous "job number" history and many job numbers may end up with NEW job numbers. It would be a big mess.

Leave the autonumber field to relate table records and never let any user see it. If you want to assign job numbers that people will see and use, create a new field that will hold that number. Then you increment the job number yourself, manually. Having that control will make sure you always have sequential numbers no matter who deletes what.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old February 9th, 2006, 08:21 PM
Registered User
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the advice. Is there another way to assign job #, without using an autonumber, that is automatic. It is more important that it is not manual than it being sequential. This number is assigned when the package is received. I do not want the people receiving to have to keep track of which number should be used.

 
Old February 10th, 2006, 08:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by bamajog
 Thank you for the advice. Is there another way to assign job #, without using an autonumber, that is automatic. It is more important that it is not manual than it being sequential.

Oh, sure. When I said "manual," I didn't mean that you couldn't program something that would increment automatically. I meant that it wasn't set automatically BY ACCESS like an autonumber.

You can create an incrementing job number very easily that will always set itself to one more than the maximum existing. I've even programmed ones that reset back to 1, say, at the beginning of the year.

There are discussions in various places about doing just this. I'm going to look them up and then post links for them for you to read in my next message.



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Number query again Brendan Bartley Access 4 August 26th, 2006 06:09 AM
problem with Auto Number Brendan Bartley Access 6 August 14th, 2006 10:13 AM
[b]Auto Number[/b] vanjamier Classic ASP Databases 1 November 18th, 2004 03:44 AM
Auto number yami56 Access 1 August 20th, 2004 11:24 AM
Auto number Sheri Dreamweaver (all versions) 0 December 22nd, 2003 03:36 PM





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