need some help is there a better way

Jon123

Registered User.
Local time
Today, 17:06
Joined
Aug 29, 2003
Messages
668
here is the code
Code:
  If (Forms![Frm1]![pRF verification].Form![read27]) >= 48 And (Forms![Frm1]![pRF verification].Form![read27]) <= 52 Then
               Me.[prffailed].Visible = False
               Me.[prfpassed].Visible = True
    Else ' outside spec
               Me.[prffailed].Visible = True
               Me.[prfpassed].Visible = False
    End If
  If (Forms![Frm1]![pRF verification].Form![read28]) >= 44 And (Forms![Frm1]![pRF verification].Form![read28]) <= 56 Then
               Me.[prffailed].Visible = False
               Me.[prfpassed].Visible = True
    Else ' outside spec
               Me.[prffailed].Visible = True
               Me.[prfpassed].Visible = False
    End If
    If (Forms![Frm1]![pRF verification].Form![read29]) >= 73 And (Forms![Frm1]![pRF verification].Form![read29]) <= 77 Then
               Me.[prffailed].Visible = False
               Me.[prfpassed].Visible = True
    Else ' outside spec
               Me.[prffailed].Visible = True
               Me.[prfpassed].Visible = False
    End If

So this is just part of the code I have to do this for 26 fields (read 27 - read 52) thay each have a different range but the msgbox is the same. Is there a better way to do this?

jon
 
Last edited:
It would be easy to loop through the controls (For/Next loop), but I don't see a pattern to the test values. Unless you have them in a table or something, I don't see another way.
 
I'd try to tidy it up a bit:
Code:
Dim strControlName(27 to 52) As String
Dim ctl(27 to 52) As Control
Dim booPassed As Boolean
Dim i As Integer

For i = 27 to 52
    'I'd have to wrestle with this to get it to work - might need to use Eval
    strControlName(i) = "read" & CStr(i)
    set ctl(i) = Forms![Frm1]![pRF verification].Form! & strControlName(i)
Next i

booPassed = True
booPassed = booPassed And (ctl(27).Value >= 48 And ctl(27).Value <= 52)
booPassed = booPassed And (ctl(28).Value >= 44 And ctl(28).Value <= 56)
booPassed = booPassed And (ctl(29).Value >= 73 And ctl(29).Value <= 77)
' etc. . . . until 52 ---> then:
Me.[prfpassed].Visible = booPassed
Me.[prffailed].Visible = Not booPassed

And as previous poster noted, I don't see a pattern, so that's as far as I could go with condensing it . . .

Cheers,
John
 
Last edited:
As an exercise in reducing code, you could do this ;-)

In the tag property of the fields you want validating put the validating values seperated by a space so Read27.Tag would be "48 52" then the only code you would need would be summat like this...


Code:
Dim f as form, c as control, fOK as boolean

Set f = Forms![Frm1]![pRF verification].Form

for each c in f

if len(c.tag) > 0 then

 fOK = (c.value between clng(left(c.tag,2)) AND clng(Right(c.tag,2))) 
 if not fOK then exit for

End if

Next

Me.[prfpassed].Visible = fok
Me.[prffailed].Visible = not fOK
 

Users who are viewing this thread

Back
Top Bottom