comparing Variant with a string ?!

MartinThe11th

New member
Local time
Yesterday, 18:19
Joined
Nov 13, 2009
Messages
9
I have a global Variant variable which contains a number

i want to compare it with a String that contains another number

within an if statement .. :

the code for testing purposes ---->

myuser is the global variant

testuser is the String Variable .


Code:
If myuser = testuser Then
    Beep
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
    Else
        MsgBox myuser
        MsgBox "test"
        MsgBox testuser
 
    End If

the output of the if statement is always false .. even with the right numbers

and the msgbox output is correct .

is it possible to compare Variant with a string ?

if not what is the best way to get over this , without going and changing

the table field datatypes !?


help is appreciated .

Martin .
 
Hi -

I'm not absolutely sure about this, since I don't have a good example to work with. However, think the Val() function might be the answer, e.g.

If val(myuser) = val(testuser) Then
...

Please post back with your results.

Best wishes - Bob
 
Why do you need to have the global variable as type variant? Does it really need to be a variant?

As well as Bob's, maybe you could try:

If CStr(myuser) = testuser Then

Chris
 

Users who are viewing this thread

Back
Top Bottom