problem wtih validation of feild.

  • Thread starter Thread starter billy_pit
  • Start date Start date
B

billy_pit

Hi,
My project is in MS Access 2002.
In that one form of data entry I am using this code for validation of
feild.

Private Sub CustomerCode_Combo_LostFocus()
If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
strMsg = "You must select Customer Code from the ComboBox."
strTitle = "CustomerCode Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.CustomerCode_Combo.Undo
Me.CustomerCode_Combo.SetFocus
End If
End Sub


Its not working properly.
only First time whenever I lostfocus of this feild and go to next
field to this field then it shows msg whatever I enter in
validation.But even if I used that line
Me.CustomerCode_Combo.Undo
Me.CustomerCode_Combo.SetFocus

its not setfocus to that feild again and its useless.
And I can go further even validation is not correct.
I don't know what's the problem?
 
Your code belongs in the Before Update event of CustomerCode_Combo. You will
need to add a line to cancel the update. Also, use some indentation. It
make the code much easier to read. Try this:

Private Sub CustomerCode_Combo_BeforeUpdate(Cancel As Integer)

If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
strMsg = "You must select Customer Code from the ComboBox."
strTitle = "CustomerCode Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.CustomerCode_Combo.Undo
Cancel = True
End If
End Sub
 
Your code belongs in the Before Update event of CustomerCode_Combo.  Youwill
need to add a line to cancel the update.  Also, use some indentation.  It
make the code much easier to read.  Try this:

Private Sub CustomerCode_Combo_BeforeUpdate(Cancel As Integer)

    If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
        strMsg = "You must select Customer Code from the ComboBox."
        strTitle = "CustomerCode Required"
        intStyle = vbOKOnly
        MsgBox strMsg, intStyle, strTitle
        Me.CustomerCode_Combo.Undo
        Cancel = True
    End If
End Sub

--
Dave Hargis, Microsoft Access MVP








- Show quoted text -

Sorry buddy but I already try that thing once but its not working at
all.Even what i am using is working at least once.so it show msg when
i leave blank field.
 
Did you put it in the Before Update event? The code should I posted should
work correctly if you put it in that event.
 
Did you put it in the Before Update event?  The code should I posted should
work correctly if you put it in that event.
--
Dave Hargis, Microsoft Access MVP






- Show quoted text -

ya put it in beforeupdate event.
can I use it in click event of submit button?
i think it will work if i use it there.
 
No, field validation in the form should always be done in the Before Update
event. Can you tell me what is not working?
 
No, field validation in the form should always be done in the Before Update
event.  Can you tell me what is not working?
--
Dave Hargis, Microsoft Access MVP






- Show quoted text -

even i used that code in BeforeUpdate event of CustomerCode Or in
form's BeforeUpdate event its not working.
I can simply add null fields to table whenever I click on submit
button.
 
Back
Top