sja13
Professional Idiot
- Local time
- Today, 19:43
- Joined
- May 3, 2017
- Messages
- 63
Hi guys....
I have a Form, who'se data source is a Query.
There are text and combo boxes on the Form, all of which have a Control Source of a field name in the Query's underlying Table.
On the Form are some Command Buttons.
There is a Command Button for "Add", and a Command Button for "Save".
Clicking "Add" executes an Event Procedure, which executes
As far as I can tell, this doesn't seem to actually add the record to the table - what it seems to do is set the default values for the text boxes and prepare the Form to accept the details of the putative next record.
When the "Save" button is clicked, if the Form is Dirty, I set the value of Dirty to False, which seems to actually write the record to the Table.
The write is also executed if I use navigation buttons to move to a different record.
However!
I also have an "Undo" Command Button.
I'm trying to handle the situation where a User has clicked "Add", realised their mistake, and then clicked "Undo" to 'cancel' the Add.
I've tried the following code options in a subroutine called when "Undo" is clicked.
(the subroutine is called with "Me" from the Command Button being received as "frm")
According to Microsoft's Help on Undo "... If the Undo method is applied to a form, all changes to the current record are lost. ..."
Not sure what that means when the Form is dealing with a new record!
(there doesn't seem to be any parameters for this, so presumably it assumes the current Form)
(at least this mentions ActiveForm)
All of them seem to leave a situation where a record is sort of partially added (sorry if that's not a brilliant description, but it's the best I can do!). The form seems to act as if there's a new record with only default values set.
As it happens, I know the record number of the record being viewed ('lngRecNo' in the following code) when "Add" was clicked, so my initial though was to include code like
This fails with "record can't be accessed".
Can any kind soul point me towards information to help me work out exactly what is happening?
My best guess at the moment is that I may need to delete the "new" record, using something like
but when I try that I get an error on the Select saying that the record can't be accessed (same error as above).
Any ideas?
I have a Form, who'se data source is a Query.
There are text and combo boxes on the Form, all of which have a Control Source of a field name in the Query's underlying Table.
On the Form are some Command Buttons.
There is a Command Button for "Add", and a Command Button for "Save".
Clicking "Add" executes an Event Procedure, which executes
Code:
DoCmd.GoToRecord , , acNewRec
When the "Save" button is clicked, if the Form is Dirty, I set the value of Dirty to False, which seems to actually write the record to the Table.
The write is also executed if I use navigation buttons to move to a different record.
However!
I also have an "Undo" Command Button.
I'm trying to handle the situation where a User has clicked "Add", realised their mistake, and then clicked "Undo" to 'cancel' the Add.
I've tried the following code options in a subroutine called when "Undo" is clicked.
Code:
frm.Undo
According to Microsoft's Help on Undo "... If the Undo method is applied to a form, all changes to the current record are lost. ..."
Not sure what that means when the Form is dealing with a new record!
Code:
DoCmd.RunCommand acCmdUndo
Code:
Screen.ActiveForm.Undo
All of them seem to leave a situation where a record is sort of partially added (sorry if that's not a brilliant description, but it's the best I can do!). The form seems to act as if there's a new record with only default values set.
As it happens, I know the record number of the record being viewed ('lngRecNo' in the following code) when "Add" was clicked, so my initial though was to include code like
Code:
DoCmd.GoToRecord , , lngRecNo
Can any kind soul point me towards information to help me work out exactly what is happening?
My best guess at the moment is that I may need to delete the "new" record, using something like
Code:
DoCmd.SetWarnings True
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Any ideas?