Validation

G

GPO

Access 2000.

I have a form with six fields. All fields are mandatory (required). I have
written the following code to warn people that if they have left any fields
blank, the record will not be saved. It is triggered by a click event on a
hyperlink label which takes them back to a main form. It works except that
when people complete data in a control and then click directly on the
hyperlink, MS Access seems to see the last field completed, as being
incomplete. It is as if an update event has not fired for that control.

Private Sub lblBack_Click()

On Error GoTo ErrorHandler

If IsNull(Me.cboDogBreed.Value) Or _
IsNull(Me.cboPetFood.Value) Or _
IsNull(Me.txtComments.Value) Or _
IsNull(Me.txtDateLoaded.Value) Or _
IsNull(Me.txtVisit_ID.Value) Or _
IsNull(Me.txtDogUniqueKey.Value) Then
If MsgBox("All fields must be complete." & vbCrLf & _
"Click [Retry] to re-enter, or [Cancel] to exit without saving
data.", _
vbRetryCancel, "Warning") = vbRetry Then
DoCmd.CancelEvent
Else
DoCmd.Close acForm, "frmDogDataEntry", acSaveYes
Forms.frmViewAnimals.sfrmViewDogs.Requery
End If
Else
DoCmd.Close acForm, "frmDogDataEntry", acSaveYes
Forms.frmViewAnimals.sfrmViewDogs.Requery
End If
Exit Sub
ErrorHandler:
MsgBox Err.Number & ": " & Err.Description

End Sub


Any ideas?

Cheers

GPO
 
C

Chris Eisert

If some of those fields are text boxes, you might want to
try the .Text property for those fields (text currently in
the field, not the saved value). I think I had a similar
problem I fixed that way.

Cheers

Chris
 

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