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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically save a new record

Status
Not open for further replies.

MortenB

Programmer
Joined
Apr 17, 2002
Messages
11
Location
LU
I have a form where a new record contains default values, default foreign keys, and auto-generated primary key. The user doesn't necessarily want to change any data before he clicks his way to the sub-form.

If a new record is not changed changed manually by the user it will not be saved using "normal" VB methods such as "runCommand acCmdSaveRecord" or by clicking on the record selector.

Is there a way to force a save in VB?
 
The save action should commence when the focus is shifted into the subform. Are you saying it does not save at this point?

From past experience, I cannot remember seeing this phenomenon. As soon as a new primary key value is generated the record is saved, either after calling the DoCmd.RunCommand acCommandSaveRecord or by shifting the focus into a subform... James Goodman
 
The point is that autonumber is not generated before the record is saved, and the record is not saved before the user has marked the record as changed by altering one of the record's controls. Catch 22! You can try it in any form that displays default data.
 
Ahh, now I understand what you mean.

I am guessing what you are trying to acheive is impossible, because this event should only occur once (from the point of view of access). Once this record with the default values has been created, it will not happen again because access would interpret it as a duplicated record. A possible solution might be to remove one of the default values from the underlying table. If you then create this assignation in the form_current event (after testing to see if it exists), & by then assigning it the data will be changed...

Does that make any sense, I am not sure if it does? I think it would work though... James Goodman
 
You've got a point. However, what I really need is to save a record which is untouched by human hands when I move to the subform. But even if the default values are displayed the record is not marked as changed. I beleive I have tried the current event with no luck. The only way I have succeded is manually reset one of the values.

Does anyone have an idea how one can force a new record to changed?
 
Ok, I just tried my suggestion above & it works perfectly. However, a duplicate record is created every time you move record. As a result this is not seen as good database design, hence access makes a tricky to accomplish...

James Goodman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top