save and then go to new record

M

mon

Hi Helpers
I would like to add to the code below so that instead of
saving and "do nothing" a new record is added.
Thanks again and again and again mon
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "@Do you wish to save the changes?"
strMsg = strMsg & "@Click Yes to Save or No to Discard
changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save
Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
 
S

Steve Schapel

Mon,

Well, if you really mean "Click Yes to Save or No to Discard changes",
and this is on the BeforeUpdate event, you really don't have to
specify the vbYes part... changes will be saved, and if you've entered
a new record, the new record will be duly added. However, if the
answer is vbNo, I think you need to cancel the update. Here's how I
would do it...
If MsgBox(strMsg, vbQuestion+vbYesNo, "Save Record?") = vbNo Then
Cancel = True
Me.Undo
End If

- Steve Schapel, Microsoft Access MVP
 
M

mon

Thanks , Steve, You are a rock. I will try it tonight,
but won't it cancel the JobNumber in the main form as
well? I still won't be able to go into the subform and
enter data for that record, will I??
-----Original Message-----
Mon,

Well, if you really mean "Click Yes to Save or No to Discard changes",
and this is on the BeforeUpdate event, you really don't have to
specify the vbYes part... changes will be saved, and if you've entered
a new record, the new record will be duly added. However, if the
answer is vbNo, I think you need to cancel the update. Here's how I
would do it...
If MsgBox(strMsg, vbQuestion+vbYesNo, "Save Record?") = vbNo Then
Cancel = True
Me.Undo
End If

- Steve Schapel, Microsoft Access MVP
 
S

Steve Schapel

Monika,

Sorry, you've lost me now. This is my simplistic way of looking at
it... If you get a prompt to confirm saving the main form record
(that's what the code you showed was all about, right?), and you say
No, i.e. discard the main form record, then why would you want to
enter a subform record related to a non-existent JobNumber? You might
have to explain a bit more about what you really want to be able to do
in practice.

- Steve Schapel, Microsoft Access MVP
 
M

mon

The JobNumber actually exists. The main form is used for
entering activities, the subform2 is used for entering
instructions which are then displayed in the other
subform1 so that each time the particular JobNumber is
selected all the instructions can be viewed and can be
ticked as completed. Subform1 has most of the records
locked so that there will be no changes, except
the "completed" checkbox. So an instruction may be
required to be entered, but not an activity. Can be vice
vers, but that's no problem since I then don't have to
leave the main form without saving an activity.
Is that any help or have I made it muddier?
 
S

Steve Schapel

Mon,

Well, no, you've made it clearer. I don't really know why you need to
have the user confirm saving changes/new records on the main form...
but let's not get into that one now! The main point probably is: how
does that then cause a problem for you if it is not confirmed? I
mean, am I right in my understanding?... If there is a new main form
record entered, or changes made to current main form record, you
prompt ther user to confirm saving the changes, ok, and then if they
say No, and the changes are therefore not saved, there's a problem of
some sort, yes?

- Steve Schapel, Microsoft Access MVP
 
M

mon

Yes Steve, the problem is if they say no, then the whole
jobnumber in main form disappears and I can't enter
instructions into the subform. I am just not sure what is
the best way to handle it. If I take the warnings off
then it is so easy for someone to save records when
perhaps they shouldn't be saved.
?????????????????thanks for your patience, steve
-----Original Message-----
Mon,

Well, no, you've made it clearer. I don't really know why you need to
have the user confirm saving changes/new records on the main form...
but let's not get into that one now! The main point probably is: how
does that then cause a problem for you if it is not confirmed? I
mean, am I right in my understanding?... If there is a new main form
record entered, or changes made to current main form record, you
prompt ther user to confirm saving the changes, ok, and then if they
say No, and the changes are therefore not saved, there's a problem of
some sort, yes?

- Steve Schapel, Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top