dbTalk Databases Forums  

Syntax Error (missing operator)

comp.databases.ms-access comp.databases.ms-access


Discuss Syntax Error (missing operator) in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
whiz
 
Posts: n/a

Default Syntax Error (missing operator) - 03-13-2010 , 07:18 PM






I'm using the DCount function in VBA. I need some other pair of eyes
to locate my problem in the WHERE clause portion. Below is one
statement of the code:

rec2("PR") = DCount("[PN]", strProgram, _
"([PROC] = " & "BUYIH" & " Or [PROC] = " & "BUY" & " Or [PROC]
= " & "BUYDS" & ") AND ([PO#PR] Like " & "G" & " & " & "*" & ")")

So, basically I want a count of PN from a table where PROC is equal to
BUYIH, BUY, or, BUYDS AND PO#PR is like G and *. Any help is
appreciated. After looking at it for awhile, the obvious don't stick
out. Thanks.

Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: Syntax Error (missing operator) - 03-14-2010 , 02:00 AM






You are trying to concatenate values into the 3rd argument for DCount().
You'll find it easier to get this right if you create a string, and then
test it in the Immediate window (Ctrl+G) to see what when wrong.)

This kind of thing:
Dim strWhere As String
strWhere = "(BUYIH IN (""BUY"", ""BUYDS"")) AND ([PO#PR] Like ""G*"")"
'Debug.Print strWhere
rec2("PR") = DCount("[PN]", strProgram, strWhere)

If the quotes don't make sense to you, here's an explanation:
http://allenbrowne.com/casu-17.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"whiz" <whizdogbob76 (AT) gmail (DOT) com> wrote

Quote:
I'm using the DCount function in VBA. I need some other pair of eyes
to locate my problem in the WHERE clause portion. Below is one
statement of the code:

rec2("PR") = DCount("[PN]", strProgram, _
"([PROC] = " & "BUYIH" & " Or [PROC] = " & "BUY" & " Or [PROC]
= " & "BUYDS" & ") AND ([PO#PR] Like " & "G" & " & " & "*" & ")")

So, basically I want a count of PN from a table where PROC is equal to
BUYIH, BUY, or, BUYDS AND PO#PR is like G and *. Any help is
appreciated. After looking at it for awhile, the obvious don't stick
out. Thanks.

Reply With Quote
  #3  
Old   
Roger
 
Posts: n/a

Default Re: Syntax Error (missing operator) - 03-14-2010 , 09:02 AM



On Mar 13, 6:18*pm, whiz <whizdogbo... (AT) gmail (DOT) com> wrote:
Quote:
I'm using the DCount function in VBA. I need some other pair of eyes
to locate my problem in the WHERE clause portion. Below is one
statement of the code:

rec2("PR") = DCount("[PN]", strProgram, _
* * * * "([PROC] = " & "BUYIH" & " Or [PROC] = " & "BUY" & " Or [PROC]
= " & "BUYDS" & ") AND ([PO#PR] Like " & "G" & " & " & "*" & ")")

So, basically I want a count of PN from a table where PROC is equal to
BUYIH, BUY, or, BUYDS AND PO#PR is like G and *. Any help is
appreciated. After looking at it for awhile, the obvious don't stick
out. Thanks.
strWhere = "[PROC] IN ('BUYIH','BUY','BUYDS') AND " & _
"([PO#PR] LIKE 'G' OR " & _
" [PO#PR] LIKE '*')"
rec2("PR") = dcount("[PN]", strProgram, strWhere)

Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Syntax Error (missing operator) - 03-14-2010 , 11:26 AM



Roger wrote:
Quote:
On Mar 13, 6:18 pm, whiz <whizdogbo... (AT) gmail (DOT) com> wrote:

I'm using the DCount function in VBA. I need some other pair of eyes
to locate my problem in the WHERE clause portion. Below is one
statement of the code:

rec2("PR") = DCount("[PN]", strProgram, _
"([PROC] = " & "BUYIH" & " Or [PROC] = " & "BUY" & " Or [PROC]
= " & "BUYDS" & ") AND ([PO#PR] Like " & "G" & " & " & "*" & ")")

So, basically I want a count of PN from a table where PROC is equal to
BUYIH, BUY, or, BUYDS AND PO#PR is like G and *. Any help is
appreciated. After looking at it for awhile, the obvious don't stick
out. Thanks.


strWhere = "[PROC] IN ('BUYIH','BUY','BUYDS') AND " & _
"([PO#PR] LIKE 'G' OR " & _
" [PO#PR] LIKE '*')"
rec2("PR") = dcount("[PN]", strProgram, strWhere)
Your like statement evaluates to
G & *
Is that the pattern you are searching for?

You could use Instr().

Reply With Quote
  #5  
Old   
Marco Pagliero
 
Posts: n/a

Default Re: Syntax Error (missing operator) - 03-19-2010 , 05:59 PM



On 14 Mrz., 01:18, whiz wrote:
Quote:
So, basically I want a count of PN from a table where PROC is equal to
BUYIH, BUY, or, BUYDS AND PO#PR is like G and *.
If G is the letter G
"([PROC] = 'BUYIH' Or [PROC] = 'BUY' Or [PROC] = 'BUYDS') AND ([PO#PR]
Like 'G*')"

If G is a string variable
"([PROC] = 'BUYIH' Or [PROC] = 'BUY' Or [PROC] = 'BUYDS') AND ([PO#PR]
Like '" & G & "'*')"

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.