Solved

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

Posted on 2002-06-05
10
172 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now