Wildcard problems inside If statement. (1 Viewer)

raggajunglist

Registered User.
Local time
Today, 07:03
Joined
Aug 30, 2007
Messages
40
I posted the below at the msdn discussions page..
Was hoping someone on this site could help also.

**********************************************************

Morning all,

Im having a bit of a problem when it comes to setting some criteria for an
If statement.
Basically im trying to say if the words "Date" or "Time" DO NOT occur
anywhere inside this combo box then perform this code......
At the moment i've got this...
If Me.cboFields.Value Like "[!*Date]" Or Me.cboFields.Value Like "[!*Time]"
Then
If Me.cboFields2.Value Like "[!*Date]" Or Me.cboFields2.Value Like
"[!*Time]" Then

.....code goes here.....

It doesn't work.. no error or anything can just click button with no
reaction.

I'm not sure if thats right but i've got another the opposite way round
where the wildcard is like
If Me.cboFields.Value Like "*Date" Or Me.cboFields Like "*Time" Then
and this one works fine.
I read that it was the ! that excluded certain data. Is that right?
Any help is greatly appreciated :)

**********************************************************

I got a response telling me...

RESPONSE: Jet doesn't recognise "!" in Like comparisons, especially inside Brackets,
which are intended to delimit object names containing spaces.

However, you can make use of the VBA Not operator, like this:

If Me.cboFields.Value Not Like "*Date*" Or Me.cboFields.Value Not Like
"*Time*" Then

Notice I've added extra asterisks. As you have it (in the working version),
the comparison is "return all entries ending in the word Date". Adding a *
to the end is saying "return all entries with the word Date anywhere in the
string".[/I]


This didn't work and gave me an error message
COMPILE ERROR: EXPECTED: EXPRESSION

The VBA help show this as an example
MyCheck = "F" Like "[!A-Z]" ' Returns False.

which leads me to believe that it would be along the lines of what i had at the start?

Like "[!*Date]"

Also date or time will always be at the end, there are no instances where it would be contained anywhere else. (eg. TotalTime, LoginDate)

Thanks for reading i know it's a lot of writing :D

Mike
 

Zigzag

Registered User.
Local time
Today, 15:03
Joined
Aug 19, 2007
Messages
386
Hi Mike

Try This

If [cboFields] Like "*date" Then
Do Something
End If

Garry
 

raggajunglist

Registered User.
Local time
Today, 07:03
Joined
Aug 30, 2007
Messages
40
Thanks for the reply,
That was indeed what i was doing wrong... putting in a .Value when it wasn't needed.
What a f00l :)
Thanks!!
 

Users who are viewing this thread

Top Bottom