Solved

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

Posted on 2002-06-05
10
187 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
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
Industry Leaders: 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!

 

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

Industry Leaders: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

756 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