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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm trying to print a report from access using VB and ADOX???

Status
Not open for further replies.

rkinrade

Programmer
Feb 1, 2003
19
US
I'm trying to print a report from an access database using an interface created in VB. Here's the code:

Private Sub cmdPrintTest_Click() 'testing the printer
Dim SelDir As String
Dim AA As Access.Application
Set AA = New Access.Application
AA.OpenCurrentDatabase DBLocation

Dim mcat As ADOX.Catalog
Dim mview As ADOX.View
Dim cmd As ADODB.Command

Set db = New ADODB.Connection
With db
.ConnectionString = ConnString
.Open
End With
If CD1.PrinterDefault = False Then CD1.ShowPrinter
'here is the loop
For i = 0 To 1
Set mcat = New ADOX.Catalog
Set mcat.ActiveConnection = db
Set mview = mcat.Views("heat")
Set cmd = mview.Command
cmd.CommandText = "SELECT CustNum,CSRNum, HName," & _
" HAddress, HCity, HState, HZip,FROM PrintCals" & WHERE EquiptID = '" & txtEquiptID(i).Text & "'"
Set mview.Command = cmd
Set mview = Nothing
Set cmd = Nothing
Set mcat = Nothing
On Error Resume Next
Dim ftemp As String

Dim filesys, newfolder As String

Set filesys = CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists("c:\ReportDir") Then
newfolder = filesys.CreateFolder("c:\ReportDir")
End If
SelDir = "c:\ReportDir"
'print report to rtf file
ftemp = "\temp" & i & ".rtf"
AA.DoCmd.OutputTo acOutputReport, "heat", "Rich Text Format", SelDir & ftemp

If chkUpdate = 0 Then 'Print the report or not
AA.DoCmd.OpenReport "heat"
End If
Next i
AA.Quit
Set AA = Nothing
Set db = Nothing
End Sub

The name of the report is "heat". The name of the query that's supposed to fill the report is also "heat". The code does update the query in the database, however the printed report contains only the labels with out the data. The RecordSource in the report properties is set to the query "heat".
Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top