Force new record on main form if no data is changed by user

I have a main form (1 reservation header) and a subform (with many reservation details). As I know the reservation header info I fill out the fields and hence the user can move immediately to the subform and add the reservation details and only change the header if necessary. The problem I have, is how to force a new record at the Load event of the main form. Nothing I have tried so far worked. Even if i try to fill some dummy data in one of fields of the main form and the erase it again - it does not create a new record. If I use lostfocus at the first field Access dies (not sure why). However, the form works fine if the user manually changes any of the main form data. Any help is greatly appreciated! Thanks Michael
mpimAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
Usually, if you use syntax similar to:

docmd.OpenForm "formname", , , , acFormAdd

it should open the form to a new record, but you might also check to make sure that the forms AllowAdditions property is set to Yes.

Are you displaying the navigation buttons on the main reservation form?  If so, you should be able to click the "new record" button in the navigation bar.

Dale
0
mpimAuthor Commented:
Thank you Dale and yes to all of your questions. I use acFormAdd, AllowAdditions is set to yes. I do show the navigation bar in the subform but not in the main form for control purpose. The system did work correctly some time ago (ie adding new record) but suddenly it changed the behaviour and now only adds a new record when i specifically change a field value in the main form. I cannot figure out what i (inadvertentely) changed to get this new and unwelcome behaviour. Any help would really be appreciated!
0
Gustav BrockCIOCommented:
Try using in the OnLoad event of the form:

Me!SomeBoundFieldToEdit.SetFocus
Me.Dirty = True

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mpimAuthor Commented:
Thank you Gustav - this worked perfectly. However, i found something really strange. The OnLoad event does not trigger on loading of the main form but only after i fill in the first field in the main form. Hence, i moved the code to OnOpen which works fine.. I will reenter the code to see if this fixes it... Again thank you!
0
Gustav BrockCIOCommented:
Oh, that sounds strange. But if it works, then be it.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You also need to add:

Me.Repaint
Me!SomeBoundFieldToEdit.SetFocus
Me.Dirty = True

 If you plan to use the OnOpen event.   Controls are not guaranteed to exist until the OnLoad event and the recordset may or may not be open yet. In fact I'm surprised that works.

<<As I know the reservation header info I fill out the fields and hence the user can move immediately to the subform and add the reservation details and only change the header if necessary.>>

  How are you filling in the controls?   If you do a .SetFocus to a control, then Me.mycontrol.text = "some value", then that should dirty the record.

 I would explore this a bit more and figure out something other than using the OnOpen.

Jim.
0
mpimAuthor Commented:
Thank you Jim - the problem is that if I move everything to OnLoad (as I had it before) the event is NOT fired until after the user enters a data. No clue why I have this behaviour. The sequence of the events is:

- Load - Subform
- Current - Subform
- Activate - Mainform

At this point the screen is shown for data input. Now if I enter any data on the main form it shows the following events:
- Current - Subform (not yet sure what triggers this)

At only once I move to the next field on the Mainform does the
- Load - Main form trigger happen!

Again, no clue why and this is the reason why I moved everything to Open. Cheers Michael
0
Dale FyeOwner, Developing Solutions LLCCommented:
mpim,

I frequently leaave the SourceObject of the subform blank, and actually hide the subform control.

This way the main form loads first.

I then use the main forms Current event to check to see whether it is on a new record.  If not, I then populate the subforms SourceObject property and LinkMaster/LinkChild properties and make the subform visible.

Then, in the Forms AfterUpdate event I make sure that the subform is displayed for further data entry.

Dale
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<At only once I move to the next field on the Mainform does the
- Load - Main form trigger happen! >>

 That almost sounds like a bug; what version of Access is this?

 The subform events do before the main's, but the OnLoad should be occurring (assuming it is bound) and the OnCurrent as well.

Jim.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.