Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoNumber In Primary Key Field 2

Status
Not open for further replies.

stazza18

IS-IT--Management
Jun 1, 2004
25
US
I have a form with 5 subforms on the main form. My problem is that the users seem to want to go to the subform 1st before any information that will allow the autonumber feature to populate my primary key. Is there any way to populate the key when you go to the new record? When they are going to the form first, they are reading a null value into the foreign key in the subform.
 
Depending on how you are initiating a New Record you can do something like this. Create a command button for the user to initiate a new record. In the OnClick event procedure of this button put the following code:

Code:
    DoCmd.GoToRecord , , acNewRec
    Me.[[i]textcontrolname[/i]] = " "
    DoCmd.RunCommand acCmdSaveRecord
    Me.[[i]textcontrolname[/i]].SetFocus

The textcontrol that you forcefeed a space into can be any one that you wish. It is this action that will create your new autonumber value. Recommendation would be for it to be your first control on the form if possibile. When the focus returns to the contol the space will be highlighted and the user can just start typing over the space.

post back if you have any questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
I may have to do something like that. The people that are using it have a lot of problems with even the simplist of systems. I already have a message box telling them to put the date of the incident before filling out the rest of the report and they still manage not to do that. I was hoping I could do something totally automated so I can take it out of the users hands. I will try your suggestion though, thanks for the reply.
 
From an interface perspective I think you may be confusing the users with so many subforms. I find once you get beyond 2 subforms you lose most users. You may want to break up the total of 6 forms into two sets of 3 forms. Your 2nd subform on your first main form could provide a link to the 2nd set of forms. There is a certain point where users are confused about how to navigate in the various subforms.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top