Mandatory Data Entry In Field Before Moving to Another Field

ih8code

Registered User.
Local time
Tomorrow, 01:15
Joined
Feb 19, 2014
Messages
15
Hi, i have a form that users will use to add new records (customers).
there is a field named VAT_Registration_no
first of all i want some code to check for duplicates in that field only,before entering the next field.If the record exists i want to show a msgbox and set focus to the vat_registration_no field.Also i want the same thing to happen if the vat_registration_no field is empty.here is what i have tried:

Private Sub VAT_registration_no_AfterUpdate()

Dim btest As Boolean
If VAT_registration_no = "" Or IsNull(Me.VAT_registration_no) Then
MsgBox "Please enter a Vat Registration No.", vbOKOnly, "error"
Me.VAT_registration_no.SetFocus
Else
btest = True
End If

End Sub



and to all other fields:

Private Sub textfield_Enter()
If Not btest Then
Me.textfield.SetFocus
End If
End Sub

if i just press enter to go straight to the second field i dont get a msg.if i write something and delete it and press enter i get the msg but when i press ok the cursor goes to the next field.i want it to go to the vat_registration_no field again.and i also want this to happen even if dont write something and then delete it.i hope you understand what i want :p thanks in advance
 
Put

Option Explicit

as the first line of the module containig your code. That should subsequently give you a clue (and is in fact recommended practice).
 
Put

Option Explicit

as the first line of the module containig your code. That should subsequently give you a clue (and is in fact recommended practice).


I'm sorry but i didn't have time to test it at work.And at home i have 64bit access so the code doesn't work there and i don't know what to do to fix it :p

After i wrote Option Explicit, i had to declare all variables.Besides that i didn't see any difference.The problem remains.When i write something in the Vat_Registration_No field and delete it and try to go to the next field,the msgbox appears but the cursor goes to the next field and i don't want that.

Thanks
 
Nevermind i thought of another way that works :) Here's what i did:

Private Sub Address_Enter()
If Me.VAT_registration_no = "" Or IsNull(Me.VAT_registration_no) Then
MsgBox "Please enter a Vat Registration No.", vbOKOnly, "Error"
Me.VAT_registration_no.SetFocus
End If
End Sub

I did that on all fields except the mandatory field and it works!! :)
 

Users who are viewing this thread

Back
Top Bottom