Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing a parameter from VB6 to Access 2000 via the OpenReport method

Posted on 2002-06-05
10
Medium Priority
?
207 Views
Last Modified: 2010-05-03
I am attempting to print an Access 2000 report from VB6. The report requires one parameter. I use the Access object's DoCmd.OpenReport method, passing the parameter in the wherecondition. I get the following error message:

Run-time error '3075':

Syntax error (missing operator) in query expression '(EmployeeName = Aimee S)'

Can anyone help with my syntax problem?

My code reads:

strWhere = "EmployeeName = " & cboEmployeeMaster(0).Text
 
With g_objAccess
  .Visible = True
  .DoCmd.OpenReport "GroupByEmployee Report",  acViewPreview, , strWhere
  .DoCmd.PrintOut  
End With
0
Comment
Question by:bob_aloo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7058068
Change:
strWhere = "EmployeeName = " & cboEmployeeMaster(0).Text

To:
strWhere = "EmployeeName = '" & cboEmployeeMaster(0).Text & "'"
0
 

Author Comment

by:bob_aloo
ID: 7058079
acperkins: I've tried that variation as well. What happens then is Access will ask me TWICE for the same parameter that I just furnished.
0
 
LVL 6

Expert Comment

by:xSinbad
ID: 7058115
Try this, just a shot in the dark.

strWhere = "EmployeeName = " & chr(34) & cboEmployeeMaster(0).Text & chr(34)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:bob_aloo
ID: 7058127
xSinbad: no change. Access still prompts me for parameter value - twice.
0
 

Author Comment

by:bob_aloo
ID: 7058160
Maybe I need to supply more information. The "GroupByEmployee Report" is based upon the "GroupByEmployee Query", which is run upon a table called "DailyShiftReports". In the design of the query, there is a column titled "EmployeeName", where SHOW is unchecked and having a criteria value of "=?". When I run either the report or the query from Access, either one will prompt for the EmployeeName parameter, as expected. When I try to open the report from VB, the first prompt from Access is asking for the "?" parameter. The second Access prompt asks for the "EmployeeName" parameter.
0
 

Author Comment

by:bob_aloo
ID: 7058165
Correction: When I run
either the report or the query from Access, either one will prompt for the "?" parameter, as
expected. When I try to open the report from VB, the first prompt from Access is asking for the "?"
parameter. The second Access prompt asks for the "EmployeeName" parameter.
0
 

Author Comment

by:bob_aloo
ID: 7058170
Also, if I do not attempt to supply the wherecondition, ie:
.DoCmd.OpenReport "GroupByEmployee Report", acViewPreview

then I am only prompted for the "?" parameter. I'm baffled.
0
 
LVL 5

Accepted Solution

by:
TheMek earned 200 total points
ID: 7059197
Try removing the '=?' from the criteria in the query and set the SHOW option to yes. Maybe the problem is that it doesn't see the field Employeename at all when you call it from VB, cos it isn't exposed to the outside.
HTH,
   Erwin
0
 
LVL 5

Expert Comment

by:TheMek
ID: 7059202
btw, I agree with acperkins and xSinbad that you'll need the quotes around the name that you pass anyways.
0
 

Author Comment

by:bob_aloo
ID: 7060406
TheMek: You were very close to identifying the problem; definitely put me on the right track. Where I ran into trouble was basing the report upon a query which required a parameter. I went back and based the report upon the original table, not the query. Then I could execute the OpenReport with, as pointed out, proper quotes around the combo box variable. Everything works beautifully now. Many thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question