Help needed Again!?

lizzieah

Registered User.
Local time
Today, 21:15
Joined
Mar 27, 2003
Messages
11
This site is so good. Glad to have help at my finger tips. All a learning process for me. Anyway
I actually got somewhere with some code,


Private Sub txtAcquisitionNo_BeforeUpdate(Cancel As Integer)

If Len(txtAcquisitionNo.Text) > 6 Then
MsgBox "Incorrect Length"
Cancel = vbCancel
End If
If IsNull(txtAcquisitionNo) Or (txtAcquisitionNo) = "" Then
MsgBox "Cant be Blank"
Cancel = vbCancel
End If
End Sub

Private Sub txtAcquisitionNo_Change()

If Len(txtAcquisitionNo.Text) > 6 Then
MsgBox "Incorrect Length"
End If

End Sub

BUT
Found out it only works after i type in a number and then delete it. I wont it to work so you cant move on to the next field until you have entered a number!

Thanks
 
Why do you have it on BeforeUpdate? What about on Exit. Then if the code will kick in if you try to you exit the field without having entered anything.
 
i have a form that only lets the user enter the next field
if all conditions that i have set are true
i dont know if there is a better way but this is what i do

declare a form module variable

dim GoBack as boolean
dim MyResponse as string
__________________________
sub CheckNumber
Goback=false

If Len(txtAcquisitionNo.Text) > 6 Then
Goback=true
Myresponse="Incorrect Length"
End If

If IsNull(txtAcquisitionNo) Or (txtAcquisitionNo) = "" Then
Goback=true
Myresponse="Cant be Blank"
End If

end sub
__________________________________
in the fields after your number field use the
on enter event
call CheckNumber
if goback=true then
msgbox Myresponse
exit sub
end if
also in the after update event for the same fields
if Goback=true then
me.txtAcquistionno.setfocus
exit sub
end if
 
Found out it only works after i type in a number and then delete it. I wont it to work so you cant move on to the next field until you have entered a number!
Maintaining the kind of control over field to field movement that you are looking for, requires lots of code and the effects really annoy the users. So I would recommend that you NOT attempt it.

If this field is defined as required in the table properties, then the error trapping should be in the field's BeforeUpdate event where you have it. Otherwise, the edit should be in the FORM's BeforeUpdate event.

You should NEVER use the change event for edits unless you are trying to do something very specific with each character that is typed. This event is fired after EVERY character. So, if 6 characters is the normal field length, then the event will fire SIX times!

EXIT is also a poor choice for edits. For one thing, it only fires if the field was entered and for another, you can't cancel the update since this event runs AFTER the BeforeUpdate event. The BeforeUpdate event is the LAST event that runs before data is actually updated so it is probably the most important event of a form and it is the most important event for error trapping. Think of it (well the Americans anyway) as "the buck stops here".
 

Users who are viewing this thread

Back
Top Bottom