PC Review


Reply
Thread Tools Rate Thread

Error in string criteria / Wildcard

 
 
Peter
Guest
Posts: n/a
 
      1st Nov 2009
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!
 
Reply With Quote
 
 
 
 
Stefan Hoffmann
Guest
Posts: n/a
 
      1st Nov 2009
hi Peter,

Peter wrote:
> 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 <--
 
Reply With Quote
 
 
 
 
Rick Brandt
Guest
Posts: n/a
 
      1st Nov 2009
On Sun, 01 Nov 2009 03:22:01 -0800, Peter wrote:

> 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
 
Reply With Quote
 
anlu
Guest
Posts: n/a
 
      1st Nov 2009
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
 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      1st Nov 2009
Hi anlu, thanks for taking your time...however i do receive Compile error:
Expected: = at the >0

Hmm

"anlu" wrote:

> 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

 
Reply With Quote
 
anlu
Guest
Posts: n/a
 
      1st Nov 2009
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" wrote:

> Hi anlu, thanks for taking your time...however i do receive Compile error:
> Expected: = at the >0
>
> Hmm
>
> "anlu" wrote:
>
> > 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

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      2nd Nov 2009
:-)

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

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

strange...

"anlu" wrote:

> 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" wrote:
>
> > Hi anlu, thanks for taking your time...however i do receive Compile error:
> > Expected: = at the >0
> >
> > Hmm
> >
> > "anlu" wrote:
> >
> > > 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

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      2nd Nov 2009
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" wrote:

> :-)
>
> now i recieve "compile error...) list separator expected...:-)
>
> i did include a space between the If and the DCount...
>
> strange...
>
> "anlu" wrote:
>
> > 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" wrote:
> >
> > > Hi anlu, thanks for taking your time...however i do receive Compile error:
> > > Expected: = at the >0
> > >
> > > Hmm
> > >
> > > "anlu" wrote:
> > >
> > > > 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

 
Reply With Quote
 
anlu
Guest
Posts: n/a
 
      2nd Nov 2009
Thanks for your feedback.
Glad to be able to help )

anlu

"Peter" wrote:

> 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" wrote:
>
> > :-)
> >
> > now i recieve "compile error...) list separator expected...:-)
> >
> > i did include a space between the If and the DCount...
> >
> > strange...
> >
> > "anlu" wrote:
> >
> > > 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" wrote:
> > >
> > > > Hi anlu, thanks for taking your time...however i do receive Compile error:
> > > > Expected: = at the >0
> > > >
> > > > Hmm
> > > >
> > > > "anlu" wrote:
> > > >
> > > > > 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

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      2nd Nov 2009
Thanks you very much Stefan and Rick.....i need to pay more attention to what
i am doing..obviously..Thanks again!

"Rick Brandt" wrote:

> On Sun, 01 Nov 2009 03:22:01 -0800, Peter wrote:
>
> > 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
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wildcard '%' acting like wildcard '_' in .net aspx page More options Gordon.E.Anderson@gmail.com Microsoft VB .NET 0 28th Mar 2007 02:02 PM
Wildcard search for string within a string? Ed Microsoft Excel Programming 0 8th Jun 2006 11:28 PM
Wildcard Selection Criteria Graham Haughs Microsoft Excel Misc 3 14th Jan 2005 09:19 AM
Wildcard string search within a string Gerry Viator Microsoft Dot NET 3 11th Nov 2004 06:22 PM
falsepart of IIF is a wildcard in criteria expression Mark Microsoft Access Queries 1 10th May 2004 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:53 AM.