Connecting Tech Pros Worldwide Forums | Help | Site Map

data entry form creates new record every time it is opened

Member
 
Join Date: Oct 2006
Location: New Jersey
Posts: 63
#1: Mar 27 '07
I have a form used for data entry of new records. Some of the fields on the form have a default value. One of the default values is derived from a combo box on a previous form (eg: create a new record for specific item).

There are some times when a user may open the form and then close it without entering anything. When this happens a new record is created that is mostly blank (except for the default values).

Is there any workaround to this? I only want a record to be created when the save button is clicked.
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 2,997
#2: Mar 27 '07

re: data entry form creates new record every time it is opened


Place a second command button next to your Save button, name it CancelSave, and use this code behind it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CancelSave_Click()
  2.    Me.Undo                                      
  3. End Sub
Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#3: Mar 27 '07

re: data entry form creates new record every time it is opened


Quote:

Originally Posted by missinglinq

Place a second command button next to your Save button, name it CancelSave, and use this code behind it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CancelSave_Click()
  2.    Me.Undo                                      
  3. End Sub

Good fix and it will help in case they start typing and decide to get out.


You may want to look at the VBA code used to populate the one control from the comboBox.

Plenty of times this can be changed:
Expand|Select|Wrap|Line Numbers
  1. Me!MyControl = Forms!ABC!ComboBox.column(0)
  2.  
To something more like this and prevent such an issue as well as keeps the next record ready to go with that same value:
Expand|Select|Wrap|Line Numbers
  1. Me!MyControl.defaultvalue = Forms!ABC!ComboBox.column(0)
See where I am going?
Member
 
Join Date: Oct 2006
Location: New Jersey
Posts: 63
#4: Mar 27 '07

re: data entry form creates new record every time it is opened


I think I see how that can be useful. No change is being made to the record, so there is nothing to save. Are there any other benefits to using default value property vs. forcing the value?

thanks for your help

Quote:

Originally Posted by Denburt

Good fix and it will help in case they start typing and decide to get out.


You may want to look at the VBA code used to populate the one control from the comboBox.

Plenty of times this can be changed:

Expand|Select|Wrap|Line Numbers
  1. Me!MyControl = Forms!ABC!ComboBox.column(0)
  2.  
To something more like this and prevent such an issue as well as keeps the next record ready to go with that same value:
Expand|Select|Wrap|Line Numbers
  1. Me!MyControl.defaultvalue = Forms!ABC!ComboBox.column(0)
See where I am going?

Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#5: Mar 27 '07

re: data entry form creates new record every time it is opened


Quote:
No change is being made to the record, so there is nothing to save. Are there any other benefits to using default value property vs. forcing the value?
Sorry if I wasn't clear the following would be just like typing it in by hand which creates the new record that isn't completely filled in.
Expand|Select|Wrap|Line Numbers
  1. Me!MyControl = Forms!ABC!ComboBox.column(0)
The following will not cause the above problem and will allow your control to populate this value for every new record they create.
Expand|Select|Wrap|Line Numbers
  1. Me!MyControl.DefaultValue = Forms!ABC!ComboBox.column(0)
Member
 
Join Date: Oct 2006
Location: New Jersey
Posts: 63
#6: Mar 27 '07

re: data entry form creates new record every time it is opened


how does this differ from the autowizard code?

Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  2.  
Quote:

Originally Posted by missinglinq

Place a second command button next to your Save button, name it CancelSave, and use this code behind it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CancelSave_Click()
  2.    Me.Undo                                      
  3. End Sub

Denburt's Avatar
Moderator
 
Join Date: Mar 2007
Location: Louisiana
Posts: 1,218
#7: Mar 27 '07

re: data entry form creates new record every time it is opened


Well if you ask me I would say it is just a nasty way of achieving the same result. The problem lies in the version of access you are using and when you upgrade, menu bars are much more likely to change than the code syntax (I just read about this issue with one of the newer releases).

Another would be:

DoCmd.RunCommand acCmdUndo

I could probably give you sixty ways to achieve the same result however I think missinglinq was on target a lot of this depends on the person and the experiences that they have had. If I did some digging I know I could find an article that stated that the DoMenuItem was on it's way out and was to be replaced by Runcmmand but they never removed it and some of the commands you use domenuitem on aren't available elswhere.

According to the VBA help file:
Quote:
The RunCommand method replaces the DoMenuItem method of the DoCmd object
O.K. so I like to back things up with facts... Simply type in Runcommand in the VBA window highlight it and press F1
Reply


Similar Microsoft Access / VBA bytes