Difficulties with Microsoft example

A

amiga1200

I have entered the following code from a Microsoft example
Private Sub Form_Open(Cancel As Integer)

' Variable to hold the default printer index.
Dim strDefaultPrinter As String

' Variable to hold the printer object.
Dim prt As Printer

' Variable to hold the report object while cycling
' through the AllReports collection.
Dim accObj As AccessObject

' Fill the printer list.
' Make sure the RowSource is empty.
Me!cmbPrinter.RowSource = ""
Me!lbxSelectReport.RowSource = ""

' Cycle through the printers installed on the machine and add them to the
combo box.
For Each prt In Application.Printers
' Use the new AddItem method to add the printer name to the combo box.
Me!cmbPrinter.AddItem prt.DeviceName
Next

' Remember the default printer.
strDefaultPrinter = Application.Printer.DeviceName

' Set the combo box to the default printer.
Me!cmbPrinter = strDefaultPrinter
Me!cmbPaperSize = 1

' Fill the report list.
For Each accObj In CurrentProject.AllReports
Me!lbxSelectReport.AddItem accObj.Name
Next

' Set the list box to the first report.
Me!lbxSelectReport.SetFocus
Me!lbxSelectReport.ListIndex = 0

End Sub

The only problem is that in the papersize combobox is a number 1.
How do I modify this to show papersize names

Amiga1200
 
M

Mark Phillipson

Hi,

There is a Enum Constant called AcPrintPaperSize which is the data type
returned by the PaperSize property of the Printer Object.

If you search for this in the Object Browser you will see what each
contstant listed.

Const acPRPSLetter = 1


To convert the values to a string you will need to build a select case
statement like the following:

Select Case prt.PaperSize
Case acPRPSA4
strPaperSize = "A4"
Case acPRPSLetter
strPaperSize = "Letter"
Case acPRPSUser
strPaperSize = "User"
End Select


--
HTH

Mark Phillipson

Free Add-Ins at; http://mphillipson.users.btopenworld.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top