Saving default form data when it loads...

itguru81

New member
Local time
Yesterday, 22:30
Joined
Jul 24, 2007
Messages
3
I have been trying to figure this out all day. Here is my situation.

I have a Form that loads giving users several options. They select one and that opens the data entry form which has several fields such as formid, current date, user name, etc. All these fields are autopopulated... but they need to be editable. Since the defaults are normally correct, I have the form do a setfocus onto the first subform control where the real data entry occurs. The form and subform are tied by a 1 to many relationship based on formID.

The problem is that when the setfocus shifts the cursor, it does NOT save the defaults values in the parent to the table, so when a user finishes data entry in the subform it returns and error that "a related record is required" in the parent table. I'm wondering how i can force access to save the parent form before the user tries to save the subform? I have tried tons of save commands, but none will save the defaults unless there is a physical click or selection of something on the parent form. Then it will save.

Anyone have a way to force access to immediately create the record when the form is opened?

Thanks
 
Where is your code to move the focus to the subform? It probably should be in the main form's Form_Load sub. If so, in the line immediatley before the setfocus line, try

docmd.RunCommand acCmdSaveRecord

Good Luck!
 
Where is your code to move the focus to the subform? It probably should be in the main form's Form_Load sub. If so, in the line immediatley before the setfocus line, try

docmd.RunCommand acCmdSaveRecord

Good Luck!

Thats exactly the problem, I tried that exact code and it does not save it. It has nothing to do with shifting focus. Taking all other functions out On Load event, and only using docmd.RunCommand acCmdSaveRecord does exactly NOTHING. Try it yourself, create a form that opens from another form... in which things are automatically populated, for example:

I have one field based on: =Environ("username")
Another one on: =Date()
The formID is populated by an autoincrement function.

Apparently access does not count these values as savable until the form itself is interacted with, which I don't understand. Can someone explain to me how i can make this work?
 
I figured out what the problem was... The "increment" function which was inputting the primary key on th new form, was being sent from the previous form, rather than the new form under "On Load" thus the value was not loading during the load event and could not save.
 

Users who are viewing this thread

Back
Top Bottom