Discussion Locked

Run a report in Access using VB6

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I would like to print address labels. I have a report in Access which I would like to run from VB6. How can I do this? What is the best possible way of generating address labels using VB6. I am using the data environment and the report designer in VB6 and it seems like I do not have the option of specifiying the number of columns and the direction of flow as can be done in access.

5 replies

by tarran

Probably the simplest way is using a Mocrosoft Word object.

I am not sure of the actual object calls, but if you can record a Macro as you carry out the following steps & use it as the source of your VB code:

Create new word document.
Selectfrom tools menu mail merge.
Configure the maind document for the labels you wich to print.
Slect your access database as your data source.
Design & print your labels.

Stop recording the macro.

Go into visual basic editor from word and cut &paste from the macro module the code you just generated into your program, editing it to automate the behavior.

I advise spending time doing this since formatting Access reports is time consuming and thankless.

by miss kitty

This is code that I have seen at several VB sites. This is a question that is asked alot since it is easier to write in Access.

Public Sub PrintAccessReport(dbname As String, rptname As String, _
preview As Boolean)
Dim objAccess As Object
On Error GoTo PrintAccessReport_ErrHandler
Set objAccess = CreateObject("Access.Application")
With objAccess
.OpenCurrentDatabase filepath:=dbname
If preview Then
'Preview report on screen.
.Visible = True
.DoCmd.OpenReport reportname:=rptname,
View:=Access.acPreview
Else
'Print report to printer.
.DoCmd.OpenReport reportname:=rptname,
View:=Access.acNormal
DoEvents
'Allow report to be sent to printer.
End If
End With
Set objAccess = Nothing
Exit Sub
PrintAccessReport_ErrHandler:
MsgBox Error$(), , "Print Access Report"
End Sub
Cathy
covcat@riverstonegrp.com

by desmondm

This works fine but one still needs to suppress the blanks between address lines

This discussion is closed to new replies.