Wildcard problems within vba....

B

bUncE

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 :)

Mike Harkess
 
S

Stuart McCall

bUncE said:
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 :)

Mike Harkess

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".
 
B

bUncE

Erm, i'm getting an error with that.

***COMPILE ERROR: EXPECTED: EXPRESSION***

I tried this before but like below as well (this way round doesn't give an
error but also doesn't do anything when i run the code.)

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

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

So surely the way i had it before is'nt far off?

If Me.cboFields.Value Like "[!*Date]" .... ?








Stuart McCall said:
bUncE said:
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 :)

Mike Harkess

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".
 
K

Keith Wilby

bUncE said:
If Me.cboFields.Value Like "*Date" Or Me.cboFields Like "*Time" Then
and this one works fine.

That's how I'd expect it to be except that I'd have an asterisk either side
of the search string. Incidentally, "Date" and "Time" are reserved words in
Access which might possibly aggravate the situation.

Keith.
www.keithwilby.com
 
J

John Spencer

IF Me.CboFields Like "*Date*" or Me.CboFields Like "*Time*" THEN
'Do nothing
ELSE
'do Something
END IF

Alternative
IF NOT (Me.CboFields Like "*Date*" or Me.CboFields Like "*Time*") THEN
'Do something here
END IF


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
P

Paolo

Hi Mike,

You can do that also with the instr function:

if instr(Me.cboFields.Value,"Date")=0 and instr(Me.cboFields.Value,"Time")=0
then
'''''if both the instr returns zero means that not date nor time are found
in your string

Do whatever you want
end if

HTH Paolo
 
B

bUncE

Ahhhhh, thankyou!!!!!!!!
Everything is now working great!!


John Spencer said:
IF Me.CboFields Like "*Date*" or Me.CboFields Like "*Time*" THEN
'Do nothing
ELSE
'do Something
END IF

Alternative
IF NOT (Me.CboFields Like "*Date*" or Me.CboFields Like "*Time*") THEN
'Do something here
END IF


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

bUncE said:
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 :)

Mike Harkess
 
B

bUncE

Ahh rite, that does make sense now i think about it.
I considered it but didn't think it would work (obviously not thinking
straight!)
Thanks for the response buddy!!!
Paolo said:
Hi Mike,

You can do that also with the instr function:

if instr(Me.cboFields.Value,"Date")=0 and instr(Me.cboFields.Value,"Time")=0
then
'''''if both the instr returns zero means that not date nor time are found
in your string

Do whatever you want
end if

HTH Paolo


bUncE said:
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 :)

Mike Harkess
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top