Error trapping dirty event

P

PaleRider

Hi,

The FirstName and LastName fields in main table have required property set
to true. In my form controls txtFirstName and txtLastName I want to trap
when a user backspaces over something they typed.

How do you trap error 3314 in the control's Dirty property. I want to allow
people to clear out what they typed in a control and move to a different
control without getting the error 3314. Is this possible?

PR
 
G

Graham Mandeno

Hi PR

I haven't tried this, but you should be able to use the Change event of the
textbox to detect when all the characters have been deleted and Undo the
textbox:

Private Sub FirstName_Change()
If Me.NewRecord and Len(FirstName.Text) = 0 Then FirstName.Undo
End Sub
 
P

PaleRider

Graham,

Ohhhh, what a wonderful little piece of code you just wrote. I had just
figured out how to trap things and was about to post back with my solution,
but your solution is much smaller and achieves the same thing. Your a genius
:)

I have included both versions below:

(Grahams version)
If Me.NewRecord And Len(Me.txtPersonnel) = 0 Then
Me.txtPersonnel.Undo
End If

(My discarded version, thanks to Graham)

If Me.NewRecord And Me.Dirty And IsNull(Me!txtPersonnel) Then
If MsgBox("A Personnel name is required data. Click OK to enter " _
& "the data, or Cancel to erase all the data in this record.", _
vbOKCancel) = vbOK Then
Cancel = True
Me!txtPersonnel.SetFocus
Else
Cancel = True
Me.Undo
End If
End If


-PR

Graham Mandeno said:
Hi PR

I haven't tried this, but you should be able to use the Change event of the
textbox to detect when all the characters have been deleted and Undo the
textbox:

Private Sub FirstName_Change()
If Me.NewRecord and Len(FirstName.Text) = 0 Then FirstName.Undo
End Sub

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

PaleRider said:
Hi,

The FirstName and LastName fields in main table have required property set
to true. In my form controls txtFirstName and txtLastName I want to trap
when a user backspaces over something they typed.

How do you trap error 3314 in the control's Dirty property. I want to
allow
people to clear out what they typed in a control and move to a different
control without getting the error 3314. Is this possible?

PR
 

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

Similar Threads

dlookup error 7
Error 3314 2
Error 3314 0
Replace MS Access Error with Custom Error 4
Catch Error 3
Form Dirty Property 1
Error Trapping 1
Required Fields in main form with subform 12

Top