Loop

Little_Man22

Registered User.
Local time
Today, 21:29
Joined
Jun 23, 2001
Messages
118
I'm looking to create a loop for a bunch of fields that require the same code. Here is an example of the code that I continually have to write:
Case "Cigarettes"
Select Case strFieldValue
Case "-1"
.FDFSetValue "Cigarettes", "X", False
Case Else
.FDFSetValue "Cigarettes", " ", False
End Select
Case "Pipe"
Select Case strFieldValue
Case "-1"
.FDFSetValue "Pipe", "X", False
Case Else
.FDFSetValue "Pipe", " ", False
End Select

So what I need is code for a loop that would ecompass these fields and the many others that I have which follow their same format.

Thanks in advance,
Ryan.
 
In your example, you are comparing the same string value (strFieldValue). If that really is the case, in other words, if, based on one field, you need to change a bunch of fields, simply do the following:


Select Case strFieldValue
Case "-1"
.FDFSetValue "Cigarettes", "X", False
.FDFSetValue "Pipe", "X", False
'other fields here
Case Else
.FDFSetValue "Cigarettes", " ", False
.FDFSetValue "Pipe", " ", False
'other fields here
End Select


If you are comparing different values, then create a function to return the values using variables:


Function fYourFunctionName(strFieldValue As String, TypeOfSmoker As String)
'strFieldValue would be the control to check, per your example
'TypeOfSmoker would be "Cigarettes", "Pipe", etc.
Select Case strFieldValue
Case "-1"
.FDFSetValue TypeOfSmoker, "X", False
Case Else
.FDFSetValue TypeOfSmoker, " ", False
End Select
End Function

Then just call the function with the proper variables each place you need it, such as

Function fYourFuntionName(Me.strFieldValue,"Pipe")

[This message has been edited by shacket (edited 08-16-2001).]
 

Users who are viewing this thread

Back
Top Bottom