View Full Version : Evaluate a condition


gear
05-11-2007, 09:08 AM
Please have a look at the following code (I am not good at VBA or SQL).

Me.[txtBox] = DLookup(“[SNum]”, “[Table1]”, “[RecID])
If Me.txtBox =>2 Then
Condition if true
Else
Condition if false
End If

I type a value in my [txtBox], a number. I want to evaluate if the typed value meets the condition or not. [SNum] is serially numbered and [RecID] is autonumber Primary Key. The above code is not working. How do I achieve this? Please help.

Malcy
05-11-2007, 10:30 AM
Hi
You have to put a condition in the third part of the DLookup, or else leave it out altogether. If you leave it out then the look will test the value of SNum. But you might be better to dim a variable rather than using a textbox -

lngTest = DLookup(“[SNum]”, “[Table1]”)
If lngTest =>2 Then
Condition if true
Else
Condition if false
End If


HTH

WayneRyan
05-11-2007, 10:35 AM
gear,


If DCount("[RecID]", "[Table1]", “[RecID] = " & Me.txtBox) > 0 Then
Condition if true <-- Autonumber in Me.txtBox exists
Else
Condition if false <-- Autonumber in Me.txtBox doesn't exists
End If


Wayne