T
True.Kilted.Scot
On my form, I have a "Save" button which is used to save the current
record. I believe that it is not necessary to save the record, as it
will be saved automatically when I move to another record, or create a
new one--perhaps someone can clarify this for me?
Anyway, when the user clicks on the "Save" button, it runs the
"cmdSaveRecord" sub which, amongst other things, executes this command:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If I trace the execution of the code, it then goes into the
"BeforeUpdate" event of the form. Within here, some validation is
performed on one of the data entry controls. If the control fails
validation, then I alert the user via MsgBox and then execute the code:
Cancel = True
The "BeforeUpdate" event exits, and returns me to the "cmdSaveRecord"
sub. However, once in here, it triggers my error trapping procedure
with the following:
Err.Number = 2501
Err.Description = The DoMenuItem action was cancelled.
Questions:
1. Do I really need the "Save" button, or can I remove it?
2. I realise the DoMenuItem line that I have has been replaced
with "RunCommand".
Should I replace the above line with "RunCommand
acCmdSaveRecord"?
3. As the form's BeforeUpdate has been cancelled, due to an
invalid entry, I obviously
don't want the record to be saved to the database. How do
I achieve this? Would I
be best advised to place the validation within the
"LostFocus" or "OnExit" event of
the desired control? Or, is there some other way of
avhieving what I'm looking for?
Many thanks & regards
Duncs
record. I believe that it is not necessary to save the record, as it
will be saved automatically when I move to another record, or create a
new one--perhaps someone can clarify this for me?
Anyway, when the user clicks on the "Save" button, it runs the
"cmdSaveRecord" sub which, amongst other things, executes this command:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If I trace the execution of the code, it then goes into the
"BeforeUpdate" event of the form. Within here, some validation is
performed on one of the data entry controls. If the control fails
validation, then I alert the user via MsgBox and then execute the code:
Cancel = True
The "BeforeUpdate" event exits, and returns me to the "cmdSaveRecord"
sub. However, once in here, it triggers my error trapping procedure
with the following:
Err.Number = 2501
Err.Description = The DoMenuItem action was cancelled.
Questions:
1. Do I really need the "Save" button, or can I remove it?
2. I realise the DoMenuItem line that I have has been replaced
with "RunCommand".
Should I replace the above line with "RunCommand
acCmdSaveRecord"?
3. As the form's BeforeUpdate has been cancelled, due to an
invalid entry, I obviously
don't want the record to be saved to the database. How do
I achieve this? Would I
be best advised to place the validation within the
"LostFocus" or "OnExit" event of
the desired control? Or, is there some other way of
avhieving what I'm looking for?
Many thanks & regards
Duncs