Stupid Syntax error

  • Thread starter April Slater via AccessMonster.com
  • Start date
A

April Slater via AccessMonster.com

Hi Everyone,

This is stupid, but I'm not very good at syntax. I have a form used to set
a filter to print reports. There are three sets of criteria to choose
from. I want the report to preview based on the criteria chosen and I
almost have it right, but I have a syntax error in the code (although I can
see that it will pull the correct information at this point) Please help
me correct the syntax so I can move on with my life :)

Here is my current code:

Private Sub Preview_Click()
On Error GoTo Err_Preview_Click

Dim strWhere As String
strWhere = "[Type of Contract] = " & Forms![Create Report]![Contract] &
Chr(34) & " And [Discipline] = " & Chr(34) & Forms![Create Report]!
[Discipline] & Chr(34) & " And [Project Name] = " & Chr(34) & Forms![Create
Report]![ProjectName] & Chr(34)

DoCmd.OpenReport "Lessons Learned", acPreview, , strWhere

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click

End Sub

The error states: Syntax error (missing operator) in query expression '(
[type of Contract]=EPIC" And [Discipline]="Hull" And [Project Name]
="Independence")'.

EPIC, Hull and Independence are the entries in the Combo box chosen by the
user.

Help Please!
 
A

April Slater via AccessMonster.com

I see your point, problem is when I add &Chr(34) to that part of the string
I get a a message box to Enter Parameter Value. That is not what I want to
do. Those values are defined in the list box on the form and I want Access
to use those, not to force redundant entry.
 
D

DebbieG

Will this work?

strWhere = "[Type of Contract] = ' " & Forms![Create Report]![Contract] & "
' " _
" And [Discipline] = ' " & Forms![Create Report]![Discipline] & " ' " _
" And [Project Name] = ' " & Forms![CreateReport]![ProjectName] & " ' "

HTH,
Debbie


message | Hi Everyone,
|
| This is stupid, but I'm not very good at syntax. I have a form used to
set
| a filter to print reports. There are three sets of criteria to choose
| from. I want the report to preview based on the criteria chosen and I
| almost have it right, but I have a syntax error in the code (although I
can
| see that it will pull the correct information at this point) Please help
| me correct the syntax so I can move on with my life :)
|
| Here is my current code:
|
| Private Sub Preview_Click()
| On Error GoTo Err_Preview_Click
|
| Dim strWhere As String
| strWhere = "[Type of Contract] = " & Forms![Create Report]![Contract] &
| Chr(34) & " And [Discipline] = " & Chr(34) & Forms![Create Report]!
| [Discipline] & Chr(34) & " And [Project Name] = " & Chr(34) &
Forms![Create
| Report]![ProjectName] & Chr(34)
|
| DoCmd.OpenReport "Lessons Learned", acPreview, , strWhere
|
| Exit_Preview_Click:
| Exit Sub
|
| Err_Preview_Click:
| MsgBox Err.Description
| Resume Exit_Preview_Click
|
| End Sub
|
| The error states: Syntax error (missing operator) in query expression '(
| [type of Contract]=EPIC" And [Discipline]="Hull" And [Project Name]
| ="Independence")'.
|
| EPIC, Hull and Independence are the entries in the Combo box chosen by the
| user.
|
| Help Please!
|
| --
|
 

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