control shouldn't have a value

W

Walter

Sorry! I hit the wrong key.
I have a form with 5 controls bound to a table. One control is the
PK(autonumber). Two controls are required in the table design. The other
two are not required but at least one needs to have data for the record to be
complete. I put the following code in the On Close event of the form to
check for this.
Private Sub Form_Close()
If IsNull(Me.ctlDOT_) _
Or IsNull(Me.ctlSerialNumber) Then
Me.Undo
End If
End Sub
In testing, the two controls show the values contained in the first record
in the table even though the controls on the form are blank. I've also
noticed that the PK control is populated when the form opens not after
entering data into one of the other controls.
 
B

Beetle

Responses inline;
I put the following code in the On Close event of the form to
check for this.

You should be doing this in the form's Before Update event, not the
Close event.
In testing, the two controls show the values contained in the first record
in the table even though the controls on the form are blank.

This is contradictory. You say the controls show values, then you say the
controls are blank.
I've also noticed that the PK control is populated when the form opens
not after entering data into one of the other controls.

It's probably just opening to an existing record, and showing you the PK
value of that record, unless you have some code or something in the
Open/Load event that would initiate a new record (seems unlikely).
 
W

Walter

I put a break in the code and the values are showing there when I hold the
cursor over the control name.

In the form's On Load event:
Private Sub Form_Load()

If Not Me.NewRecord Then
DoCmd.GoToRecord , , acNewRec
End If

Me.cboBrand.SetFocus

End Sub

I moved the code to the Before Update event and that corrected the problem
of having partial records. It still creates a PK value upon opening which is
discarded at close if no record is entered ie: open the form and hit the
close button. It's no issue but that doesn't happen in my other forms.
 

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