Solved

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

Posted on 2002-06-05
10
177 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 54
Determine Range to Select 5 48
Cannot Load VB6 on Windows 10. Installed OK but error on opening existing project. 7 85
Add a task in Outlook from access 11 39
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

786 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