Question

Access 2010 here.

I have a nagging concern with two of my three subforms. The subforms are each bound to their own table with unique information; the main form is also bound to its own table. All three subform tables are in a one-to-one relationship with the main form table. My first subform acts normally in that when there is a new record, all of its bound entry fields are displayed blank. The code in Form_Current():

  Private Sub Form_Current()

  'Determine what should be displayed'
  'Do stuff to prepare the current record for display'

  If Me.NewRecord = True Then
  Me.Stuff = Null
  End If

  End Sub

is present for all three subforms and the main form to display older records and to ready the form for data entry by resetting check boxes etc; there is no code to "reset" the entry fields themselves. Unfortunately, the other two subforms retain data from the last entered record and display it as if the user wants to re-enter the same data. The thing is, this data means nothing unless the user explicity enters the data entry field and then leaves it by any means. Simply moving on to the next record without entering the data entry fields doesn't save the phantom pre-entered data (which is expected as the record in the subform was never made as the user never entered data in the subform).

What I am looking for is either a form-specific option to open a clean record by default, or VBA code that can ensure empty data fields on new record. I have tried actively re-querying the subforms when a new record is opened in the main form without success. I have also tried pre-setting values to "" upon entering a new record, which did work to an extent, but seeing as one subform works properly, I am after a solution, not a workaround.

Was it helpful?

Solution

Go into Design View on the subform, and in the subform's properties find the setting called "Data Entry".

Changing that to "Yes" will change the subform's behavior.

From then on all the subform do is be clear and ready accept data for new records. After a record is entered, the subform is cleared and will be ready for another brand new record.

This option is available for any form.

I would update the other two subforms with this setting. Easy, and no VBA necessary!

OTHER TIPS

Continuing Thoughts:

What I found with the "Data Entry" setting set static to "Yes" on a subform is that old-record browsing functionality no longer worked. New records were clean of old data, but now old records also didn't show what had been entered; because the "Data Entry" setting prepares them for new data. What had to be done was actively set the "Data Entry" setting on each subform depending on if the record was "New" or not:

Private Sub Form_Current()

'Determine what should be displayed'
'Do stuff to prepare the current record for display'

If Me.NewRecord = True Then
 Me.Stuff = Null
 Me!SubFormName0.Form.DataEntry = True
 Me!SubFormName1.Form.DataEntry = True
 Me!SubFormName2.Form.DataEntry = True
Else
 Me.Stuff = DatabaseNumbers
 Me!SubFormName0.Form.DataEntry = False
 Me!SubFormName1.Form.DataEntry = False
 Me!SubFormName2.Form.DataEntry = False
End If

End Sub

Thanks again for the help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top