paulmcdonnell
09-07-2001, 04:48 AM
Hi Guys,
I'm trying to check conditions using code ie. If x=1 or x=2 or x=3 then ... perform event.
I want to be able to do this with the criteria being the entries in a table. i.e. If x is listed in table y then perform event.
I can't quite manage to get this right and I'm not sure of the code ... Can anyone help
Cheers
paul
shacket
09-07-2001, 05:05 AM
Not entirely sure what you want to do there. What does "if x is in the table" mean? You mean, for each record, if the value of Field A is x then do this...?
Check the Select Case statement. This may help you. Or post a little more detail and we'll hash it through.
[This message has been edited by shacket (edited 09-07-2001).]
paulmcdonnell
09-07-2001, 05:36 AM
OK, What I mean is that I have a table which has a list of parameter values eg. record 1 is A, record 2 is B, record 3 is C.
What I need to do is a condition to return true if a text box on my form matches any entry within the parameter table.
does this help shacket?
cheers
shacket
09-07-2001, 07:03 AM
OK, so if the text box matches any entry in the table (in a given field), you want the condition to return true. There are two ways to do this:
The first way is to put the code in the form as a sub. The second is to set it up as a function so you could call it from more than one place. Below is the function. I am assuming that you'll be able to transfer it to a sub if needed. (I am not sure of your coding abilities, so I apologize if I am talking over or under you! http://www.access-programmers.co.uk/ubb/smile.gif
Function fMatchParameter(Letter As String) As Long
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("YourParameterTableName", dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
'if the record matches, the function is true and exit the function
If Letter = rs!FieldName Then
fMatchParameter = 1 'True
Exit Function
End If
rs.MoveNext
Loop
'if the code gets to here, it has looped through all records
'and not found a match. Therefore, the function
'is not true
fMatchParameter = 0
End Function
You would then call that statement by something like:
If fMatchParameter(YourTextBoxName) = True Then
<such and such>
Else
<such and such>
End If
HTH
[This message has been edited by shacket (edited 09-07-2001).]