Results 1 to 2 of 2
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    print pdf


    all using 2010. I have a report that when I select to print; it has a pop save dialog to save as pdf. I go into the print dialog and see that it's set to print adobe pdf. I can set it to print to the printer but when I try to print again; I have to select the printer again. Im trying to have it set up to print via vba programming but cannot until I can get this to default to printer instead of adobe pdf. My other reports are printing fine but this one. Help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You could 1st set default printer to the pdf printer in a macro...

    '' IN A MACRO as the EVENT put
    RUNCODE
    SetDefaultPrinter("PDF PRINTER")



    Code:
         ''''PUT IN A MODULE 
    
    Private Const HWND_BROADCAST As Long = &HFFFF&
    Private Const WM_WININICHANGE As Long = &H1A
    ' The following code allows one to read, and write to the WIN.INI files
    ' In win 2000 the printer settings are actually in the registry. However, windows
    ' handles this correctly
    '
    Private Declare Function GetProfileString Lib "kernel32" _
       Alias "GetProfileStringA" _
      (ByVal lpAppName As String, _
       ByVal lpKeyName As String, _
       ByVal lpDefault As String, _
       ByVal lpReturnedString As String, _
       ByVal nSize As Long) As Long
    Private Declare Function WriteProfileString Lib "kernel32" _
       Alias "WriteProfileStringA" _
      (ByVal lpszSection As String, _
       ByVal lpszKeyName As String, _
       ByVal lpszString As String) As Long
    Private Declare Function SendMessage Lib "user32" _
       Alias "SendMessageA" _
      (ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       lparam As Any) As Long
    
    Function SetDefaultPrinter(strPrinterName As String) As Boolean   Dim strDeviceLine As String
       Dim strBuffer     As String
       Dim lngbuf        As Long
        
      ' get the full device string
      '
       strBuffer = Space(1024)
       lngbuf = GetProfileString("PrinterPorts", strPrinterName, "", strBuffer, Len(strBuffer))
      
      'Write out this new printer information in
      ' WIN.INI file for DEVICE item
      If lngbuf > 0 Then
         
         strDeviceLine = strPrinterName & "," & _
                         fstrDField(strBuffer, Chr(0), 1) & "," & _
                         fstrDField(strBuffer, Chr(0), 2)
                         
         Call WriteProfileString("windows", "Device", strDeviceLine)
         SetDefaultPrinter = True
         
         ' Below is optional, and should be done. It updates the existing windows
         ' so the "default" printer icon changes. If you don't do the below..then
         ' you will often see more than one printer as the default! The reason *not*
         ' to do the SendMessage is that many open applications will now sense the change
         ' in printer. I vote to leave it in..but your case you might not want this.
         '
         
         'Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")
        
      Else
         SetDefaultPrinter = False
      End If
           
    End Function
    
    Private Function fstrDField(mytext As String, delim As String, groupnum As Integer) As String
       ' this is a standard delimiter routine that every developer I know has.
       ' This routine has a million uses. This routine is great for splitting up
       ' data fields, or sending multiple parms to a openargs of a form
       '
       '  Parms are
       '        mytext   - a delimited string
       '        delim    - our delimiter (usually a , or / or a space)
       '        groupnum - which of the delimited values to return
       '
       
    Dim startpos As Integer, endpos As Integer
    Dim groupptr As Integer, chptr As Integer
    chptr = 1
    startpos = 0
     For groupptr = 1 To groupnum - 1
        chptr = InStr(chptr, mytext, delim)
        If chptr = 0 Then
           fstrDField = ""
           Exit Function
        Else
           chptr = chptr + 1
        End If
     Next groupptr
    startpos = chptr
    endpos = InStr(startpos + 1, mytext, delim)
    If endpos = 0 Then
       endpos = Len(mytext) + 1
    End If
    fstrDField = Mid$(mytext, startpos, endpos - startpos)
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 07-29-2014, 01:05 PM
  2. Replies: 6
    Last Post: 03-01-2014, 07:07 AM
  3. Replies: 1
    Last Post: 12-03-2012, 03:15 PM
  4. Replies: 5
    Last Post: 10-26-2011, 02:59 PM
  5. Replies: 0
    Last Post: 02-22-2011, 05:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums