Validation (1 Viewer)

mark curtis

Registered User.
Local time
Today, 16:51
Joined
Oct 9, 2000
Messages
457
Dear all,

I have two form and subform both in datasheet view.

My question is that if I enter the subform without inserting a record in the main form I want to pop a msgbox up to let them know the ID key needs activating by populating a field.

The parent child relationship works ok but I want to let the users know in a more freindly way that they have violated key realationship without the default message.

I used the following but it seems not to like it. Basically when the child record receives the focus it looks to the parent record and if it contains the text <Mandatory> or is null then it should send the focus back to the parent record via a message box.

Private Sub Form_GotFocus()
If IsNull(Forms![frmDocumentRegister]![fsubProduct]![txtProductName]) Or Forms![frmDocumentRegister]![fsubProduct]![txtProductName] = "<Mandatory>" Then
Forms![frmDocumentRegister]![fsubProduct]![txtProductName].SetFocus
MsgBox "njnh"
End If
End Sub

Thanks
Mark
 

Fornatian

Dim Person
Local time
Today, 16:51
Joined
Sep 1, 2000
Messages
1,396
Mark,

you have two options, set the subform as disabled and only enable it one a record is created, using a lost focus event after a critical field entry or (which I prefer) use the Form_Error event on the subform to test for the DataErr(error number) and then take appropriate action.

To find out which error it is use Msgbox "The DataErr number is " & DataErr

having trapped that DataErr you can then display your own tailored error message,and move focus
you'll have to set Response = acDataErrContinue to prevent the std error msg from showing.


Hope that helps a little

Ian
 

mark curtis

Registered User.
Local time
Today, 16:51
Joined
Oct 9, 2000
Messages
457
Ian,

Thanks for the reply.

You don't have an example of how to code a msgbox for error trapping?

It would help loads.

Thanks as always
Mark
 

Fornatian

Dim Person
Local time
Today, 16:51
Joined
Sep 1, 2000
Messages
1,396
These are some examples from one of my databases...

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case Is = 2279 'input mask error
DispMsg ("The code must be five alpha-numeric characters and must be unique from all other codes")
Response = acDataErrContinue
Case Is = 3022 'duplicate primary key entry
DispMsg "This code already exists, please choose a unique code"
Response = acDataErrContinue
Me.Code.SetFocus
Me.Code = "?????"
Case Else
Response = acDataErrDisplay
MsgBox DataErr
End Select
End Sub

Ian
 

Users who are viewing this thread

Top Bottom