Data Validation (1 Viewer)

Bechert

Registered User.
Local time
Today, 11:12
Joined
Apr 11, 2003
Messages
59
Hello, I have a continuous sub-form on a main form.
I need to be able to validate the data entered on each row of the sub-form as well as perform contextual validation between rows, including when a row with specific values is not present.

I also want to ensure when a validation error occurs the user cannot exit the main form until the error is corrected.

Where should this validation take place?

Thanks,
Bill
 

John Big Booty

AWF VIP
Local time
Today, 22:12
Joined
Aug 29, 2005
Messages
8,263
I believe the validation would need to take place in the Before Update event of the field.
 

Bechert

Registered User.
Local time
Today, 11:12
Joined
Apr 11, 2003
Messages
59
Thanks John, the Before_Update works for the fields on the current record.

I also need to be able to do detect, based on the Treament Code value (e.g., 97001) on one record, that a record with Treatment Code 'G8988' exists.


Bill
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:12
Joined
Feb 19, 2002
Messages
42,970
You need to do that in the BeforeUpdate event of the control or of the form. Use DLookup() or DCount() to determine if the record exists. This code needs to only run for new records or existing records where the treatment code has changed so -
Code:
If Me.NewRecord = True OR Me.txtTreatmentCode <> Me.txtTreatmentCode.OldValue Then
    If DCount(..) > 0 Then
        Msgbox "This Treatment code already exists for this patient.",vbOKOnly
        Cancel = True
        Exit Sub
    End If
End If
 

Users who are viewing this thread

Top Bottom