Multiple Field Validation at Form Level

sohailcdc

Registered User.
Local time
Today, 10:05
Joined
Sep 25, 2012
Messages
55
Hi there

I am trying to learn Access during my free time, to learn something
I learn a lot through this web form

Anyways, here's my situation, I am getting following error
"MS Access can't find the field "|" referred in your expression"

I am trying to validate the field behaviour before SAVE
Instead of writing a code at each textbox, I am trying to use WHILE LOOP

There're 12 textbox and 3 validations at each textbox
1) Can't Empty
2) If Combo box listIndex value = "1" then textbox value can't be more than 29
3) If Combo box listIndex value other than "1" then textbox value can't be more than 31

Following codes are working perfectly at individual textbox level
However, when I use with WHILE LOOP, getting error message
"MS Access can't find the field "|" referred in your expression"

Dim count1 As Integer
Dim check1 As Integer

count1 = 1
While count1 < 13

Me.[txtbox" & count1 & "].SetFocus
If Me.[combox" & count1 & "].ListIndex = 1 Then
If Me.[txtbox" & count1 & "] > 29 Then
check1 = check1 + 1
MsgBox "Validation Option 2", vbInformation, "Error"
Me.[txtbox" & count1 & "].SetFocus
Exit Sub
End If
Else
If Me.[txtbox" & count1 & "] > 31 Then
check1 = check1 + 1
MsgBox "Validation Option 3", vbInformation, "Error"
Me.[txtbox" & count1 & "].SetFocus
Exit Sub
End If
End If
Me.[txtbox" & count1 & "].SetFocus
If IsNull([txtbox" & count1 & "]) = True Then
check1 = check1 + 1
MsgBox "Validation Option 1", vbInformation, "Error"
Me.[txtbox" & count1 & "].SetFocus
Exit Sub
End If
count1 = count1 + 1
Wend

Thanks for any help in advance
 
Me.[txtbox" & count1 & "].SetFocus is not a valid way to reference an object.

Me.Controls("[txtbox" & count1 & "]").SetFocus
 
Try this type of thing:

If Me("txtbox" & count1) > 29 Then
 

Users who are viewing this thread

Back
Top Bottom