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!

Print dialog box

Status
Not open for further replies.

ztm

IS-IT--Management
Jul 19, 2001
34
US
Hello all,

I’ve got an Access form that prints an existing excel spreadsheet from a command button. I want it to prompt the user for number of copies and printer (print dialog box) but otherwise, run in the background. I accomplished this on another project I did and it was clean and worked well, but I accidentally deleted that project (oops) Now, I can’t seem to get it right. The code I have works, but it’s chunky and no dialog box. I’ve tried using the doCmd.RunCommand acCmdPrint, but can’t figure out how to tell it what file to print.

Dim xlApp as Object

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
xlApp.workbooks.Open "spreadsheet.xls"
xlApp.activesheet.PrintOut
xlApp.displayalerts = False
xlApp.Quit
 
Try something like this:
Code:
sMsg = InputBox("", "How many copies?", "1")
If IsNumeric(sMsg) = True Then
    iCopies = CInt(sMsg)
Else
   MsgBox "Invalid number of copies!"
   Exit Sub
End If

ActiveWindow.SelectedSheets.PrintOut Copies:=iCopies

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top