Solved

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

Posted on 2002-06-05
10
194 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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 50 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

724 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