Validation NOT working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello boys,

I have a TextBox in a Subform. I set the sub form as a Dialog, DataEntry=Yes
where the user can type a value. I also have a validation using VB where the
textbox can not accept zeros but apparently it is not working 'cause every
time I use the down-arrow key, inserts a new record with zeros in the Textbox.

The default value of the TextBox is zero, but it is to put something in it.

Any help will be appreciate
 
If the default value is 0, then it will put a 0 in the text box for new
records. The validation rules kick in when you manually enter the value 0.
 
Hello boys,

I have a TextBox in a Subform. I set the sub form as a Dialog, DataEntry=Yes
where the user can type a value. I also have a validation using VB where the
textbox can not accept zeros but apparently it is not working 'cause every
time I use the down-arrow key, inserts a new record with zeros in the Textbox.

The default value of the TextBox is zero, but it is to put something in it.

Remove the default value property (if you don't want it to be zero, don't make
zero the default!!!) and make the field Required, for starters.

Post your validation code. There's evidently something wrong with it but we
can't fix code we can't see.

John W. Vinson [MVP]
 
You are right, I forgot to post the code. Here is the code in this form:

Private Sub LECTURA_BeforeUpdate(Cancel As Integer)
If (LECTURA = "0.00") Or (LECTURA = "0") Then
MsgBox "Valuer NOT allowed", vbOKCancel + vbCritical, "Zero value!"
Cancel = True
Else
ID_SKU = "00329"
ID_LECTURA = 1
NO_LINEA = Form.CurrentRecord
MsgBox Form.CurrentRecord
End If

End Sub


Again, I appreciate your help
 
Here is the code in this form:

Thanks. Try getting away from the text string represenation:

Private Sub LECTURA_BeforeUpdate(Cancel As Integer)
If Val(LECTURA) = 0 Then
MsgBox "Valuer NOT allowed", vbOKCancel + vbCritical, "Zero value!"
Cancel = True
Else
ID_SKU = "00329"
ID_LECTURA = 1
NO_LINEA = Form.CurrentRecord
MsgBox Form.CurrentRecord
End If

End Sub

John W. Vinson [MVP]
 
Thanks. Try getting away from the text string represenation:

Private Sub LECTURA_BeforeUpdate(Cancel As Integer)
If Val(LECTURA) = 0 Then

Since this is in the BeforeUpdate event, LECTURA has not been set
yet. One needs in this case to refer to the .text property of the
control
If Val(me.LECTURA.text) = 0 Then


Q
 
Thanks guys. It worked!
--
César Parrales


John W. Vinson said:
Thanks. Try getting away from the text string represenation:

Private Sub LECTURA_BeforeUpdate(Cancel As Integer)
If Val(LECTURA) = 0 Then
MsgBox "Valuer NOT allowed", vbOKCancel + vbCritical, "Zero value!"
Cancel = True
Else
ID_SKU = "00329"
ID_LECTURA = 1
NO_LINEA = Form.CurrentRecord
MsgBox Form.CurrentRecord
End If

End Sub

John W. Vinson [MVP]
 
Since this is in the BeforeUpdate event, LECTURA has not been set
yet.

Eh? I've never had to do that. The .Value property is set at BeforeUpdate time
(just not at Change time).

John W. Vinson [MVP]
 

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

Back
Top