Nope - that doesn't work. It shows the access ide but it dissapears again after a second.
I also need to know how to send the parameter.
Main Topics
Browse All TopicsI have built a report in Access that when invoked from access prompts me for a StartDate. When entered the reports runs fine.
I would like to invoke this report from my visual basic program, so that when invoked the report simply appears on the screen.
Here is my current function, where I am attempting to invoke this report.
When I call this function, I pass to it the dateStart which is the StartDate required by the report.
But, I am still prompted for a StartDate and no report appears.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
on closer look the problem is that the remote db is closed straight away, you need a way to suspend the code before passing back to the current db. Doevents yields execution to the operating system, it will not suspend the code. the simplest way i can think of is to
1) declare the
Dim ac As Access.Application
variable OUTSIDE your sub, say at the module level so that it remains in scope during your sub
2) in the close event of your remote db's report, add
Quit
such that that instance of Access and the remote db will shut down when you close the report
3) remove
ac.CloseCurrentDatabase
Set ac = Nothing
this is closing the remote db before you have a chance to view it
4) in you current app, if you need to reuse the ac object variable then set it to nothing before resetting it
Set ac = Nothing
>1) It still requires me to manually enter the StartDate parameter
the parameter is passed to the WHERE condition argument so you paraString needs to include the relevant field/s
so for eg if the fields is called "dtStartDate"
paraString needs to something like "dtStartDate = '20090115'"
is the name of your field StartDate?
if you are having problem with # then try ', ie
paraString = Replace("StartDate = 'dt'", "dt", dateStart)
>i just want to view the report - not have access open thus giving access to the data
if you want to open remote db with certain restrictions then you'll have to modify the startup parameters of your remote db, menu tools>startup
uncheck options like "display database window", "allow full menus" etc.
you may want to leave "use access special keys" so that you can bypass it and bring those options backup at a later date.
or you can write code to do this which would be just more work
Set ac = New Access.Application
ac.Visible = True
ac.OpenCurrentDatabase DBPATH
Dim paraString As String
paraString = "StartDate = '" & dateStart & "'"
ac.DoCmd.OpenReport "qry_Crosstab_Results", acViewPreview, , paraString
Still prompts me to enter the StartDate (yes that is the field name). I tried with # and ' and nothing at all.
The Report is bound to a crosstab query which is fed from another query. Is this affecting it? Can i still pass a parameter to the report?
>The Report is bound to a crosstab query which is fed from another query. Is this affecting it? Can i still pass a parameter to the report?
you should be able to. also check that the date parmeter actually exists in your report data!
test it with a hardcoded a value.
manually open your remote db and run something like code below
DoCmd.OpenReport "qry_Crosstab_Results", acViewPreview, , "StartDate = '1 Jan 2008'"
or
DoCmd.OpenReport "qry_Crosstab_Results", acViewPreview, , "StartDate = #1 Jan 2008#"
does it open the report correctly?
dont forget that with queries Access defaults to that awful American date format of mmddyy so you may have to format your date variable explictly for eg:
format("10/01/09","dd/mmm/
returns 10/Jan/2009
that means then the problem is not the remote db code but the query/s itself. Are any of the queries (crosstab query itself and the ones that it is based on) driving the report queries that require user input? (ie a parameter query itself, where the critieria is something like =[enter your value])
i've already tested the code i posted on a test remote db and report and it works fine.
Actually, my queries are listed here.
http://www.experts-exchang
Thanks for sticking with me! =)
well good news for me is that i'm about to go on annual leave to see my man federer who barely won his 2nd round match. so i'll get to see him in the final on saturday.
so i have 1 hour before i knock off at work to try to sort this one out. i think it is the cross tab query which produces dynamic column headers which causes the parameter message....damn.
let me think this through.
the problem is you have a parameter query in qryGetDailyShifts.
StartDate is not a field in a table but a parameter.
the where condition (paraString) in the docmd.openreport method
ac.DoCmd.OpenReport "qry_Crosstab_Results", acViewPreview, , paraString
is to filter the report with a value for a field not a parameter input.
btw you have the wrong report name, it should be
rpt_Crosstab_Results and not qry_Crosstab_Results
--------------------------
now off the top of my head, to get around this parameter,
create a table say tmpDate with field StartDate. this table should only contain a single record.
you will dynamically delete records from this table and insert with your required startdate.
then join to this table in your query qryGetDailyShifts
so that query becomes:
SELECT DISTINCT tblShifts.EmployeeNumber, EmployeeName, ShiftDate, d.startdate, concatshifts(tblShifts.Emp
FROM tmpDate AS d, tblShifts INNER JOIN tblEmployee ON tblShifts.EmployeeNumber=t
WHERE ShiftValid=Yes And ShiftDate Between
d.StartDate And DateAdd("d",6,d.StartDate)
--------------------------
then remove
PARAMETERS StartDate DateTime;
from the crosstab query qry_Crosstab_Results
--------------------------
the vb code would be:
now this will remove the parameter prompt as your queries are no longer prompting for user input.
the last bit you need to fix (post a new question as its unlikely others will want to wad thru this thread) is your report. the report design is bound to date values which are the current date values in this weeks shift. by next week your report will not work because the dates will be different.
as i'm now on leave i'll give you a suggestion. rather than bound the report to the crosstab, create another table say trptShifts and dynamically delete and insert into this table the contents of the cross tab query.
this table should have column headers monday, tuesday, ... etc rather than the actual dates.
the critical thing is the
1) number of columns in your report must be fixed which is ok now as it is 6 days from the start date.
2) use the column position (via recordset) of the cross tab query to identify which column to insert into the monday, tuesday ... columns etc.
3) you also need to insert the headers of the cross tab query as a row entry into this report table. you might have to use a text field to hold the data as it will be a mixture of dates and time.
if all of this is too much trouble then dont use the crosstab output but the normalised output of the actual source tables.
Business Accounts
Answer for Membership
by: frankyteePosted on 2009-01-14 at 14:12:37ID: 23378313
you need to make it visible like below
Dim ac As Access.Application
Set ac = New Access.Application
ac.OpenCurrentDatabase DBPATH
ac.Visible = True
... etc