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
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