UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Set Printer To .pdf If No Default Printer Setup, Access 2010    
 
   
Brepea
post Jan 17 2018, 03:34 AM
Post#1



Posts: 597
Joined: 11-January 09
From: UK


Hi - not sure how common this is, but for me there are an handful of people who seemingly never print anything - and as a result - when they come to view my reports (always in acPreview mode) - they get an error if no default printer has been selected/setup within Windows.

Does anyone know how i can set the output format to .pdf (i guess) - IF no default printer is set? So i suppose we need to first (1) check whether a default printer is setup (not sure how i can do this - so would appreciate help here) - then (2) if no printer setup = 0 or something then use .pdf format...?

Appreciate the help in advance.
Go to the top of the page
 
ranman256
post Jan 17 2018, 10:07 AM
Post#2



Posts: 883
Joined: 25-April 14



if no printer send report to PDF when user clicks the print button

CODE
sub btnPrint_click()

vRpt="myReport"

if GetDefaultPrinter() = "" then   'print pdf
   vFile = "c:\" & vRpt
   docmd.OutputTo acOutputReport ,vRpt,acFormatPDF,vFile
else
  docmd.openReport vRpt
endif
end sub



Paste this code into a module

CODE
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


Function GetDefaultPrinter() As String
   Dim strDefault    As String
   Dim lngbuf        As Long

   strDefault = String(255, Chr(0))
   lngbuf = GetProfileString("Windows", "Device", "", strDefault, Len(strDefault))
   If lngbuf > 0 Then
      GetDefaultPrinter = fstrDField(strDefault, ",", 1)
   Else
      GetDefaultPrinter = ""
   End If

End Function

This post has been edited by ranman256: Jan 17 2018, 10:09 AM
Go to the top of the page
 
Brepea
post Jan 18 2018, 05:35 AM
Post#3



Posts: 597
Joined: 11-January 09
From: UK


Do you need some reference applied to get this module to compile?

it's failing on

CODE
GetDefaultPrinter = [b]fstrDField[/b](strDefault, ",", 1)
Go to the top of the page
 
ranman256
post Jan 18 2018, 07:43 AM
Post#4



Posts: 883
Joined: 25-April 14




sorry i missed this part....


CODE
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
Go to the top of the page
 
Brepea
post Jan 19 2018, 06:39 AM
Post#5



Posts: 597
Joined: 11-January 09
From: UK


Thanks...Can you help further...?

So users can only access the "print" facility using shortcut menu (i've created on right-click) - oh and I guess using Ctrl+P. How /where do i call the function from to check whether default printer exists? Does Access check for default printer when using clicks to view report in acPreview (as this is the load format) - or only when they Ctrl+P or right-click/print?

I basically want to check for a default printer for the user when they login - so if one has been setup - do nothing otherwise warn user that they need to setup a default printer before attempting to print reports.
Go to the top of the page
 
Brepea
post Feb 5 2018, 08:21 AM
Post#6



Posts: 597
Joined: 11-January 09
From: UK


Hi - is anyone able to help re:

QUOTE
So users can only access the "print" facility using shortcut menu (i've created on right-click) - oh and I guess using Ctrl+P. How /where do i call the function from to check whether default printer exists? Does Access check for default printer when using clicks to view report in acPreview (as this is the load format) - or only when they Ctrl+P or right-click/print?

I basically want to check for a default printer for the user when they login - so if one has been setup - do nothing otherwise warn user that they need to setup a default printer before attempting to print reports.
Go to the top of the page
 
mmadani
post Feb 5 2018, 11:56 AM
Post#7



Posts: 355
Joined: 27-June 08



Hello;

Check out this thread in UA here : http://www.UtterAccess.com/forum/index.php?showtopic=2029460


Good Luck;

Mike
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th December 2018 - 03:12 PM