Error in string criteria / Wildcard

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi all. I have an issue with the DCount and wildcard searc...i recevie String
Error or expected = when i try to run this. All i want to do is to
DoCmd.OpenForm after Then..IF no records are found in the FruitQuery,,,


IfDCount("*'","FruitQuery","[Fruits]='*" & Me.Search & "*'")>0 Then

Thanks!
 
hi Peter,
Hi all. I have an issue with the DCount and wildcard searc...i recevie String
Error or expected = when i try to run this. All i want to do is to
DoCmd.OpenForm after Then..IF no records are found in the FruitQuery,,,

IfDCount("*'","FruitQuery","[Fruits]='*" & Me.Search & "*'")>0 Then
There is a ' too much and you need another operator:

E.g.
Dim Count As Long
Dim Search As String

Search = Replace(txtSearch.Value, "'", "''")
Count = DCount("*", _
"FruitQuery", _
"[Fruits] LIKE '*" & Search & "*'")
If Count > 0 Then
Else
End If


mfG
--> stefan <--
 
Hi all. I have an issue with the DCount and wildcard searc...i recevie
String Error or expected = when i try to run this. All i want to do is
to DoCmd.OpenForm after Then..IF no records are found in the
FruitQuery,,,


IfDCount("*'","FruitQuery","[Fruits]='*" & Me.Search & "*'")>0 Then

Thanks!

If this is exactly as it appears in your code you need a space after "If".

You should also use "Like" instead of "=" since you are including
wildcard characters, but I don't think that would give you an error,
perhaps just incorrect results.
 
Hi Peter,

You should leave out the ' in the first argument - that is probably what
generates the error. Also, if you want to use wild cards in your criteria,
you should use "like" in stead of "=", otherwise you won't get many hits.
I.e. your code should look like this:

If DCount("*","FruitQuery","[Fruits] like '*" & Me.Search & "*'")>0 Then


Regards,
anlu
 
Hi anlu, thanks for taking your time...however i do receive Compile error:
Expected: = at the >0

Hmm
 
Hi Peter,

In your original post, there was no space between "If" and "DCount" - if
that is still the case, you will get the compile error.
Could that be it?

anlu

Peter said:
Hi anlu, thanks for taking your time...however i do receive Compile error:
Expected: = at the >0

Hmm

anlu said:
Hi Peter,

You should leave out the ' in the first argument - that is probably what
generates the error. Also, if you want to use wild cards in your criteria,
you should use "like" in stead of "=", otherwise you won't get many hits.
I.e. your code should look like this:

If DCount("*","FruitQuery","[Fruits] like '*" & Me.Search & "*'")>0 Then


Regards,
anlu
 
:-)

now i recieve "compile error...) list separator expected...:-)

i did include a space between the If and the DCount...

strange...

anlu said:
Hi Peter,

In your original post, there was no space between "If" and "DCount" - if
that is still the case, you will get the compile error.
Could that be it?

anlu

Peter said:
Hi anlu, thanks for taking your time...however i do receive Compile error:
Expected: = at the >0

Hmm

anlu said:
Hi Peter,

You should leave out the ' in the first argument - that is probably what
generates the error. Also, if you want to use wild cards in your criteria,
you should use "like" in stead of "=", otherwise you won't get many hits.
I.e. your code should look like this:

If DCount("*","FruitQuery","[Fruits] like '*" & Me.Search & "*'")>0 Then


Regards,
anlu
 
Hi anlu...you are very correct..and i am very...impatient...i appologise..
It works very well when you acctualy change the criterias everywhere in the
code..:-):-)

Thanks a lot anlu..you made my week!

Peter said:
:-)

now i recieve "compile error...) list separator expected...:-)

i did include a space between the If and the DCount...

strange...

anlu said:
Hi Peter,

In your original post, there was no space between "If" and "DCount" - if
that is still the case, you will get the compile error.
Could that be it?

anlu

Peter said:
Hi anlu, thanks for taking your time...however i do receive Compile error:
Expected: = at the >0

Hmm

:

Hi Peter,

You should leave out the ' in the first argument - that is probably what
generates the error. Also, if you want to use wild cards in your criteria,
you should use "like" in stead of "=", otherwise you won't get many hits.
I.e. your code should look like this:

If DCount("*","FruitQuery","[Fruits] like '*" & Me.Search & "*'")>0 Then


Regards,
anlu
 
Thanks for your feedback.
Glad to be able to help :o)

anlu

Peter said:
Hi anlu...you are very correct..and i am very...impatient...i appologise..
It works very well when you acctualy change the criterias everywhere in the
code..:-):-)

Thanks a lot anlu..you made my week!

Peter said:
:-)

now i recieve "compile error...) list separator expected...:-)

i did include a space between the If and the DCount...

strange...

anlu said:
Hi Peter,

In your original post, there was no space between "If" and "DCount" - if
that is still the case, you will get the compile error.
Could that be it?

anlu

:

Hi anlu, thanks for taking your time...however i do receive Compile error:
Expected: = at the >0

Hmm

:

Hi Peter,

You should leave out the ' in the first argument - that is probably what
generates the error. Also, if you want to use wild cards in your criteria,
you should use "like" in stead of "=", otherwise you won't get many hits.
I.e. your code should look like this:

If DCount("*","FruitQuery","[Fruits] like '*" & Me.Search & "*'")>0 Then


Regards,
anlu
 
Thanks you very much Stefan and Rick.....i need to pay more attention to what
i am doing..obviously..Thanks again!

Rick Brandt said:
Hi all. I have an issue with the DCount and wildcard searc...i recevie
String Error or expected = when i try to run this. All i want to do is
to DoCmd.OpenForm after Then..IF no records are found in the
FruitQuery,,,


IfDCount("*'","FruitQuery","[Fruits]='*" & Me.Search & "*'")>0 Then

Thanks!

If this is exactly as it appears in your code you need a space after "If".

You should also use "Like" instead of "=" since you are including
wildcard characters, but I don't think that would give you an error,
perhaps just incorrect results.



--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
.
 
Back
Top