Saving record when opening another form?

winkmich

Registered User.
Local time
Today, 13:05
Joined
Jun 21, 2002
Messages
18
Hi there,

I have the following problem:

I have a form which includes a command button.
Clicking this button another form will be opened. This 2nd form needs information from the first form (ID etc.)

If I open the 2nd form the record is NOT saved yet.

Apart from just pressing "Save record" in the Records menu,
is there a neat trick to include a line (like save record or so) in the event builder

----------
stDocName = "Name of 2nd Form"

stLinkCriteria = "[ContactsID]=" & Me![ContactsID] (somewhere here, I guess)
DoCmd.OpenForm stDocName, , , stLinkCriteria
----------

Thanks in advance,

Michael.
 
If I understand you correctly…

You could do something like this on the OnClick Event of your button;

DoCmd.Save acForm, "THE NAME OF THE FORM THAT YOU WANT TO SAVE"

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = “The Form Name You Want To Open"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Hope This Helps

Don
 
If I got you right :) you meant to save the form.

what I want to do is to save the RECORD before the 2nd form gets opened. because the record is not saved the 2nd form is not related to any record - which means that I can't enter any data.

So, I though about sort of a "short-cut" to avoid pressing "save record" in the first form.

but thanks, anyway.
 
Sorry Man...I guess I am still asleep this morning...I misread your question...Try this instead...

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = “The Form Name You Want To Open"
DoCmd.OpenForm stDocName, , , stLinkCriteria


The above code will save the currnet record...Unless I am still asleep... :D

***NOTE TO SELF***

SELF...Do not try and answer question until you have had at least three cups of coffee.

Don
 
Last edited:
Yeah, I'm with donbettis on this. I've actually had this problem in the past and I fixed by:

1. drawing a command button on the form
2. choosing "Record Operations" from the wizard and then "Save Record"
3. Rob the code out of the "Save" button you have created and put it in the appropriate place in the other command button, to save the record before opening the linked form.
4. Delete the "Save" button code
5. Delete the "Save" button itself.

This is the way that I do this simply because it is easier by far for me to do it this way than to try to remember the exact syntax to save the record.
 
Actually, the preferred syntax is:

DoCmd.RunCommand acCmdSaveRecord

I know that the wizards still generate code of the type posted by donbettis, but Microsoft recommends the code that I posted. You'll notice that the menu reference is to Access version 7 which I think is the internal version for A95. We're up to A2002 which I think is version 10.
 
Pat,

Thanks for the syntax tip. I will definitely keep that in mind and try to use that in the future.
 
See we all learn new things...

Now only if I could remember the things I have learned... So many new things...so few brain cells left...

Thanks Again Pat

Don
 
hi there,

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

worked perfectly - Thanks!

And just a hint: I still (have to) work with Access 97 - so sometimes it's good to have the "old stuff" :)

And Don: Better have two glasses of tap water right after getting up in the morning. That's keeps you awake. Really!

Okay, wish you all a nice weekend.

Bye Mike.
 
I work with 97 too, I don't use the menu item, in this case if you are using a pop up modal form your code will not work. Old dinosaur programmers do not post codes / suggestions without good reason, without a reference list you will not know what many of the menu items are actually doing.
 

Users who are viewing this thread

Back
Top Bottom