Hi.
if a value is enterd into a field on a form which is a reqired,unique
indexed field in the underlying table, how can messages from db be supressed
when it is maybe already in ?
I trap these wrong inputs and wrote my own stuff but I would like to handle
such wrong input with custom made messages alltogether so no default message
from db should show up after my handling
could i do this at all and if so how ?
Gina
>Hi.
>
[quoted text clipped - 7 lines]
>
>could i do this at all and if so how ?
Use the Form's BeforeUpdate event to trap the error before it happens.
If you set the Cancel parameter to True it won't attempt to write the
record, so no error message will be generated.
You say you trap the wrong inputs and wrote my own stuff - could you
share what it is that you wrote? It can probably be adapted to avoid
the error message!
John W. Vinson[MVP]
Gina - 08 Apr 2005 08:43 GMT
Hi John.
Thanks for your answer!
Here's what I 've got so far:
_______________________
Private Sub Kennzeichen_BeforeUpdate(Cancel As Integer)
CheckKennzeichenOK
Cancel = Not (Me.GetCarRegOK)
If Me.GetCarRegOK = False Then
MsgBox "Please input a valid car registration number!!", _
vbExclamation, "Input or change car registration number"
SetCarRegOK (False)
End If
End Suib
_______________________
Public Static Sub CheckCarRegOK()
Dim result
If Not IsNull(Me.CarReg) Then
' take out spaces and other unnice stuff
outStr = ErrorChecking.fStringValid(Form__frmCar.CarReg.Value)
' if regnumber already in db
result = ErrorChecking.CheckDoubleRegNr(outStr)
If result > 0 Then
' is it in for current customer
result = ErrorChecking.CheckCarForOwner(outStr,
Form__frmCar.CustID)
If result = 1 Then
' yes it is in for current customer
Me.SetCarRegOK (True)
Me.cmdDeleteCar.Enabled = True
SetCheckedKennzeichen (outStr)
Else
result = ErrorChecking.GetNameOfCarOwner(outStr)
' get real owner for carRegNumber
Me.SetCarRegOK (False)
Me.cmdDeleteCar.Enabled = False
MsgBox "Car registration number already exists for customer"
_
& UCase(result) & " !! ", vbCritical, _
"Car registration number not valid"
End If
Else
Me.SetCarRegOK (True)
Me.cmdDeleteCar.Enabled = True
SetCheckedKennzeichen (outStr)
End If
Else
Me.SetCarRegOK (False)
Me.cmdDeleteCar.Enabled = False
End If
' have to do that visible stuff as otherwiese eventhough the caregnum
entered in
' Form__frmCar.CarReg the details of that car ( work - in subform frmWork
and workdetails assubform of frmWork )
' ar displayed and set the db in kind of shock!! :(
If Me.GetNewEntryClicked = True Then
Form__frmWork.Visible = True
Me.SetNewEntryClicked (False)
End If
If Me.GetDelCarClicked = True Then
Form__frmWork.Visible = True
Me.SetDelCarClicked (False)
End If
End Sub
_______________________
Public Static Function GetCarRegOK() As Boolean
GetCarRegOK = carRegOK
End Function
_______________________
Public Sub SetCarRegOK(val As Boolean)
carRegOK = val
If Me.GetNewEntryClicked = True Then
Form__frmWork.Visible = True
ElseIf Me.GetDelCarClicked = True Then
Form__frmWork.Visible = True
Else
Form__frmWork.Visible = val
End If
End Sub
________________________
It's probably a bit .... :-| .. ?
Gina
> >Hi.
> >
[quoted text clipped - 17 lines]
>
> John W. Vinson[MVP]
Gina - 11 Apr 2005 10:14 GMT
John,
I think my problem doesn't result from code I posted ... (before update) I
assume the error messages come from either the after update or lost focus
event ....
I have to go through it ... step by step !!!
I am new to this access coding ... so I think I had (or still have) some
problems in getting these events right!!! :(
Gina
> >Hi.
> >
[quoted text clipped - 17 lines]
>
> John W. Vinson[MVP]