Get Files To Print (VBA)

DekHog

New member
Local time
Today, 15:03
Joined
May 15, 2007
Messages
3
Since there is no introduction section, I'll just say a quick 'Hi' to all in here...

Ok, I hadn't used Access until 2 months ago, and had never seen VBA until 2 weeks ago, so that sets the standard I'm at I suppose.

The problem is my daughter and I have both been toiling trying to get the final project done for her postgrad, and the last thing she wanted was an MS Access project, but that's what she got.

Hard to explain without seeing it, but basically she was handed and old-ish database which was saving files from a form to the A: drive, plus a couple of other problems which we've managed to sort out.

I've managed to replace the automatic output to the A: drive with a 'Browse' dialog, and the files are now output to the folder selected. The only problem is that they want them to print out at the same time, and we just don't know how to get the code to do it.

I've attached the database (it's quite simple and really small) and the code is behind the two buttons marked 'Publish To File' and 'Publish With Abbreviated Institution,' both of which are on the initial form that opens.

I feel like we've come so far and learned so much (the hard way) but are now stuck at the final hurdle. Can anyone please help out?
 

Attachments

Since there is no introduction section, I'll just say a quick 'Hi' to all in here...

Ok, I hadn't used Access until 2 months ago, and had never seen VBA until 2 weeks ago, so that sets the standard I'm at I suppose.

The problem is my daughter and I have both been toiling trying to get the final project done for her postgrad, and the last thing she wanted was an MS Access project, but that's what she got.

Hard to explain without seeing it, but basically she was handed and old-ish database which was saving files from a form to the A: drive, plus a couple of other problems which we've managed to sort out.

I've managed to replace the automatic output to the A: drive with a 'Browse' dialog, and the files are now output to the folder selected. The only problem is that they want them to print out at the same time, and we just don't know how to get the code to do it.

I've attached the database (it's quite simple and really small) and the code is behind the two buttons marked 'Publish To File' and 'Publish With Abbreviated Institution,' both of which are on the initial form that opens.

I feel like we've come so far and learned so much (the hard way) but are now stuck at the final hurdle. Can anyone please help out?

Based on what I see in the database it looks like you are just outputting tables to RTF files, the simplest way to print hard copies of these would probably be to print the tables from Access.

Code:
Sub PrintTables()
DoCmd.OpenTable "YourTableName"
DoCmd.PrintOut
DoCmd.Close acTable, "YourTableName"
End Sub

Of course this will only print them to whatever the default printer is, if you want to be able to print them to a specific printer you would need to change the default which can be done through VBA but that seems beyond the scope of what you are trying to accomplish.

You can of course substitute a variable name for the string or an array of all the table names and just loop through it until everything is printed.
 
Yes, the default printer would be fine for them, and it is the RTF files I'd be wanting to print, and would definitely just want to loop through them until they are all printed. I'm just not sure where the code for this would go though?

I obviously want to print the RTF files as the data in these is gathered and formatted from the tables A thru T. So, without being totally stupid, I'm thinking that the output in these RTF files isn't actually saved in Access anywhere, and isn't only what's in the tables, as it would be pointless having two buttons doing the same thing.

I hope I'm making sense here? :confused:
 
Last edited:
Yes, the default printer would be fine for them, and it is the RTF files I'd be wanting to print, and would definitely just want to loop through them until they are all printed. I'm just not sure where the code for this would go though?

I obviously want to print the RTF files as the data in these is gathered and formatted from the tables A thru T. So, without being totally stupid, I'm thinking that the output in these RTF files isn't actually saved in Access anywhere, and isn't only what's in the tables, as it would be pointless having two buttons doing the same thing.

I hope I'm making sense here? :confused:

Code:
For intFor = Asc("A") To Asc("T")
          'output A to T
            DoCmd.OutputTo acOutputTable, _
            Chr(intFor) & "Tab", acFormatRTF, _
            strFolderName & "\" & Chr(intFor) & "file.rtf"
        Next

Each file is created from it's own table Atab through Ttab, from what I can see the output files look identical to the table format so I think you would be able to just print the tables out as I suggested, however if you want to print the files off you could try the Shell command.

Code:
Call Shell("Print " & "YourFileHere")

Trying to print something that is not inherently part of a program is very difficult to do in my experience. Here is a VB example I have from years ago.

Code:
Const PT_LINETO = &H2
Const PT_BEZIERTO = &H4
Const PT_CLOSEFIGURE = &H1
Const DI_APPBANDING = &H1
Const DI_ROPS_READ_DESTINATION = &H2
Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Type DOCINFO
        cbSize As Long
        lpszDocName As String
        lpszOutput As String
        lpszDatatype As String
        fwType As Long
End Type
Private Declare Function PolyDraw Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, lpbTypes As Byte, ByVal cCount As Long) As Long
Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" (ByVal hdc As Long, lpdi As DOCINFO) As Long
Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Pt(1 To 2) As POINTAPI, bTypes(1 To 2) As Byte, DI As DOCINFO
    'fill the DOCINFO-structure
    DI.cbSize = Len(DI)
    DI.lpszDocName = "API-Guide Code Demonstration"
    DI.lpszOutput = vbNullString
    DI.lpszDatatype = vbNullString
    'starts a print job
    Call StartDoc(Printer.hdc, DI)
    'prepare the printer driver to accept data
    Call StartPage(Printer.hdc)
    Pt(2).x = 50
    Pt(2).y = 30
    bTypes(1) = PT_LINETO
    bTypes(2) = PT_LINETO
    'draw a set of line segments
    PolyDraw Printer.hdc, Pt(1), bTypes(1), 2
    'inform the device that the application has finished writing to a page
    Call EndPage(Printer.hdc)
    'end the print job
    Call EndDoc(Printer.hdc)
End Sub
 
Sorry, I don't understand - yes, I could print out the contents of the Access tables, but this isnt' exactly what's in the RTF files as (the way this noob sees it anyway) the subs for the buttons then call the subs 'instit' & 'subindex' to format the output. If the PrintOut sub you showed will print the exact output of the RTF files, where does it go, and where/how do I call it?

I'd probably like to use the Call Shell thing, but really don't understand the syntax for using it, and only have until Friday!!

I think I'm getting worse instead of better now... :(
 
Sorry, I don't understand - yes, I could print out the contents of the Access tables, but this isnt' exactly what's in the RTF files as (the way this noob sees it anyway) the subs for the buttons then call the subs 'instit' & 'subindex' to format the output. If the PrintOut sub you showed will print the exact output of the RTF files, where does it go, and where/how do I call it?

I'd probably like to use the Call Shell thing, but really don't understand the syntax for using it, and only have until Friday!!

I think I'm getting worse instead of better now... :(

The instit and subindex functions are formatting the data and putting it into multiple tables which are then being exported as RTF files, open one of the tables up if you don't believe me, they contain the same formatting as the RTF files. The print out command would go inside your loop

Code:
      For intFor = Asc("A") To Asc("T")
          'output A to T
            DoCmd.OutputTo acOutputTable, _
            Chr(intFor) & "Tab", acFormatRTF, _
            strFolderName & "\" & Chr(intFor) & "file.rtf"
            DoCmd.OpenTable Chr(intFor) & "Tab"
            DoCmd.PrintOut
            DoCmd.Close acTable, Chr(intFor) & "Tab"
        Next
 

Users who are viewing this thread

Back
Top Bottom