Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a report in access from VB 1

Status
Not open for further replies.

Agent009

Programmer
Apr 4, 2003
96
0
0
IE
Hey All,

This is the code i have so far for printing a report in access. I want to print out the report with its data in it. When i print it seems to just come with a blank report + only the headings appear. How do i print the report with populated information?

Dim nGroup_ID As Integer
'Dim ObjAccess As Access.Application
Dim objAccess As Object
Dim strDBDir As String
Dim strSQL As String
Dim dtFromDate As String
Dim dtToDate As String

Screen.MousePointer = vbHourglass

strDBDir = m_Conn.Properties("Data Source")

'Set objAccess = New Access.Application
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase strDBDir, False

objAccess.DoCmd.OpenReport "rptVisitorsIn", acViewDesign

strSQL = "SELECT tblmain.ID,tblmain.VisitorName,tblmain.VisitorCompany,tblmain.Visiting,tblmain.CarReg,tblmain.Date,tblmain.time,tblmain.DateOut from tblmain"

objAccess.Reports(0).RecordSource = strSQL
objAccess.DoCmd.OpenReport "rptVisitorsIn", acViewNormal

objAccess.CloseCurrentDatabase
objAccess.Quit acQuitSaveNone

Screen.MousePointer = vbDefault

Thanks in advance,

Agent009
 
I mean, create the query IN Access, and then set the report's data source to it.
 
Ive created the query but where do i set the reports data source to it?
 
In Access select the report and open it in design mode.
Then click the menu "View" "Properties"
A properties sheet will show. Click on the Data tab and in the DataSource field add the name of the query.

If the property sheet for the report doesn't show up, but instead one for a section or control, then click on the grey unused area below the report (you can also just double click there and the prop. page will show)
 
Thanks a million VBOldTimer, my code was relatively ok, but it wa sthe properties of the query that i had incorrect!

Thanks again, and remember,

"Writing an application in Visual Basic is alot like making love to a beautiful woman" - Swiss Tony
 
Ok everything is going fine, but how do i change the query in access from a simple 'select * from TABLENAME' query to a 'select * from TABLENAME where FIELDNAME is Null'?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top