From: "hari yanto har_i20002000@yahoo.com [belajar-access]" <belajar-access@yahoogroups.com>
Date: Apr 16, 2015 10:08 PM
Subject: Re: [belajar-access] membuat script untuk Print
To: <belajar-access@yahoogroups.com>
Cc:
  
  Agus....,
  
  Coba gunakan cara ini.
  
  1. Buat modul baru di jendela modul, yang bertujuan mengkoleksi semua printer yang di jaringan dan komputer local. Isinya:
  
  Option Compare Database
  Option Explicit
  
  '************************
  ' Printer setup module
  ' Set/retrieves the default printer - originaly for VB6
  ' Works for A97/a2000
  ' This is minimal code.
  ' Albert D.Kallal - 01/13/2002
  ' Rev history:       Date           Who                   notes
  '                    01/13/2002     Albert D. kallal
  '
  ' I wrote this after looking at some the code on the net. Some of the routines
  ' to change a printer were approaching 500 + of lines of code. Just the printer
  ' constant defs was over 100 lines of code! Yikes!
  ' I use only TWO API's (the 3rd one is optional). There is a total of only 4 functions!
  ' KISS is the word. Keep it simple stupid. I don't care about device drivers, or the
  ' port number. All these routines just work with the simple printer name. If you do
  ' actually care about the device driver and port stuff..then use the one of many
  ' examples available on the net. Those other examples also deal with margins, orientation
  ' etc.
  '
  ' You can paste this code into a module..and away you go
  '
  '************************
  ' How to use
  ' To get the default printer
  
  '        debug.print   GetDefaultPrinter
  ' To set the default printer
  '        debug.print SetDefaultPrinter("HP Laser JET")
  '  above returns true if success.
  ' To get a list of printers suitable for a listbox, or combo
  '        debug.print GetPrinters
  '
  ' that is all there folks!
  '
  ' Thus, when printing a report, you can:
  '
  '       1) save the default printer into a string
  '              strCurrentPtr = GetDefaultPrinter
  '       2) switch to your report printer
  '              SetDefaultPrinter strReportsPtr
  '       3) print report
  '       4) switch back to the default printer
  '              SetDefaultPrinter strCurrentPtr
  '
  
  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
     
           
  
  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
  
  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
  
  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
  
  Function GetPrinters() As String
     
     ' this routine returns a list of printers, separated by
     ' a ";", and thus the results are suitable for stuffing into a combo box
     
     Dim strBuffer  As String
     Dim strOnePtr  As String
     Dim intPos     As Integer
     Dim lngChars   As Long
     
     strBuffer = Space(2048)
     lngChars = GetProfileString("PrinterPorts", vbNullString, "", strBuffer, Len(strBuffer))
     
     If lngChars > 0 Then
        intPos = InStr(strBuffer, Chr(0))
       Do While intPos > 1
          strOnePtr = Left(strBuffer, intPos - 1)
          strBuffer = Mid(strBuffer, intPos + 1)
          If GetPrinters <> "" Then GetPrinters = GetPrinters & ";"
          GetPrinters = GetPrinters & strOnePtr
          intPos = InStr(strBuffer, Chr(0))
       Loop
     Else
        GetPrinters = ""
     End If
     
   End Function
  
  Public Function testPrintersGet()
  
  Debug.Print GetDefaultPrinter
     Debug.Print GetPrinters
     
     
  End Function
  
  2. Pada form yang akan dijadikan tempat eksekusi, buat combo box. Beri nama combo1.
  
  3. Beri event pada saat form on load:
  
  Private Sub Form_Load()
      Me.Combo1.RowSource = GetPrinters
      Me.Combo1 = GetDefaultPrinter
  End Sub
  
  // ini akan memunculkan seluruh printer, yang menjadi default adalah default komputer
  
  4. Untuk mengubah default printer, yaitu tatkala user memilih printer sesuai keinginan, beri event ini:
  
  Private Sub Combo1_AfterUpdate()
      SetDefaultPrinter (Me.Combo1)
  End Sub
  
  5. Tunggu hingga printer benar-benar berubah. 
  
  6. Setalah berubah, lakukan uji coba.
  
  Semoga bisa membantu dan memberi semangat.
  
  Hariyanto (Surabaya)
  www.lpjkjatim.com
  
  3. 
  
  --------------------------------------------
  On Tue, 14/4/15, Agus Erwanto erwanto_agus@yahoo.co.id [belajar-access] <belajar-access@yahoogroups.com> wrote:
  
  Subject: [belajar-access] membuat script untuk Print
   To: belajar-access@yahoogroups.com
   Date: Tuesday, 14 April, 2015, 4:28 PM
   
   
    
   
   
   
     
   
   
       
         
         
         Dear Master,
   
   
   
   mohon di bantu untuk membuat vba untuk print form di access,
   tetapi sebelum di print bisa memilih Print mana yang akan
   digunakan, karena kadang print defaulnya terpakai.
   
   
   
   selama ini saya menggunakan vba print yang langsung print
   saja form yang tampil, seperti dibawah :
   
   
   
   Private Sub Command62_Click()
   
   On Error GoTo Err_Command62_Click
   
   
   
   DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
   
       DoCmd.PrintOut acSelection
   
   
   
   Exit_Command62_Click:
   
       Exit Sub
   
   
   
   Err_Command62_Click:
   
       MsgBox Err.Description
   
  
  Resume Exit_Command62_Click
   
   End Sub
   
   
   
   mohon pencerahannya
   
   
  
  regards,
   
   
   
   aguserw
   
   
   
       
        
   
       
       
   
   
   
   #yiv0826940107 #yiv0826940107 --
     #yiv0826940107ygrp-mkp {
   border:1px solid #d8d8d8;font-family:Arial;margin:10px
   0;padding:0 10px;}
   
   #yiv0826940107 #yiv0826940107ygrp-mkp hr {
   border:1px solid #d8d8d8;}
   
   #yiv0826940107 #yiv0826940107ygrp-mkp #yiv0826940107hd {
   color:#628c2a;font-size:85%;font-weight:700;line-height:122%;margin:10px
   0;}
   
   #yiv0826940107 #yiv0826940107ygrp-mkp #yiv0826940107ads {
   margin-bottom:10px;}
   
   #yiv0826940107 #yiv0826940107ygrp-mkp .yiv0826940107ad {
   padding:0 0;}
   
   #yiv0826940107 #yiv0826940107ygrp-mkp .yiv0826940107ad p {
   margin:0;}
   
   #yiv0826940107 #yiv0826940107ygrp-mkp .yiv0826940107ad a {
   color:#0000ff;text-decoration:none;}
   #yiv0826940107 #yiv0826940107ygrp-sponsor
   #yiv0826940107ygrp-lc {
   font-family:Arial;}
   
   #yiv0826940107 #yiv0826940107ygrp-sponsor
   #yiv0826940107ygrp-lc #yiv0826940107hd {
   margin:10px
   0px;font-weight:700;font-size:78%;line-height:122%;}
   
   #yiv0826940107 #yiv0826940107ygrp-sponsor
   #yiv0826940107ygrp-lc .yiv0826940107ad {
   margin-bottom:10px;padding:0 0;}
   
   #yiv0826940107 #yiv0826940107actions {
   font-family:Verdana;font-size:11px;padding:10px 0;}
   
   #yiv0826940107 #yiv0826940107activity {
   background-color:#e0ecee;float:left;font-family:Verdana;font-size:10px;padding:10px;}
   
   #yiv0826940107 #yiv0826940107activity span {
   font-weight:700;}
   
   #yiv0826940107 #yiv0826940107activity span:first-child {
   text-transform:uppercase;}
   
   #yiv0826940107 #yiv0826940107activity span a {
   color:#5085b6;text-decoration:none;}
   
   #yiv0826940107 #yiv0826940107activity span span {
   color:#ff7900;}
   
   #yiv0826940107 #yiv0826940107activity span
   .yiv0826940107underline {
   text-decoration:underline;}
   
   #yiv0826940107 .yiv0826940107attach {
   clear:both;display:table;font-family:Arial;font-size:12px;padding:10px
   0;width:400px;}
   
   #yiv0826940107 .yiv0826940107attach div a {
   text-decoration:none;}
   
   #yiv0826940107 .yiv0826940107attach img {
   border:none;padding-right:5px;}
   
   #yiv0826940107 .yiv0826940107attach label {
   display:block;margin-bottom:5px;}
   
   #yiv0826940107 .yiv0826940107attach label a {
   text-decoration:none;}
   
   #yiv0826940107 blockquote {
   margin:0 0 0 4px;}
   
   #yiv0826940107 .yiv0826940107bold {
   font-family:Arial;font-size:13px;font-weight:700;}
   
   #yiv0826940107 .yiv0826940107bold a {
   text-decoration:none;}
   
   #yiv0826940107 dd.yiv0826940107last p a {
   font-family:Verdana;font-weight:700;}
   
   #yiv0826940107 dd.yiv0826940107last p span {
   margin-right:10px;font-family:Verdana;font-weight:700;}
   
   #yiv0826940107 dd.yiv0826940107last p
   span.yiv0826940107yshortcuts {
   margin-right:0;}
   
   #yiv0826940107 div.yiv0826940107attach-table div div a {
   text-decoration:none;}
   
   #yiv0826940107 div.yiv0826940107attach-table {
   width:400px;}
   
   #yiv0826940107 div.yiv0826940107file-title a, #yiv0826940107
   div.yiv0826940107file-title a:active, #yiv0826940107
   div.yiv0826940107file-title a:hover, #yiv0826940107
   div.yiv0826940107file-title a:visited {
   text-decoration:none;}
   
   #yiv0826940107 div.yiv0826940107photo-title a,
   #yiv0826940107 div.yiv0826940107photo-title a:active,
   #yiv0826940107 div.yiv0826940107photo-title a:hover,
   #yiv0826940107 div.yiv0826940107photo-title a:visited {
   text-decoration:none;}
   
   #yiv0826940107 div#yiv0826940107ygrp-mlmsg
   #yiv0826940107ygrp-msg p a span.yiv0826940107yshortcuts {
   font-family:Verdana;font-size:10px;font-weight:normal;}
   
   #yiv0826940107 .yiv0826940107green {
   color:#628c2a;}
   
   #yiv0826940107 .yiv0826940107MsoNormal {
   margin:0 0 0 0;}
   
   #yiv0826940107 o {
   font-size:0;}
   
   #yiv0826940107 #yiv0826940107photos div {
   float:left;width:72px;}
   
   #yiv0826940107 #yiv0826940107photos div div {
   border:1px solid
   #666666;height:62px;overflow:hidden;width:62px;}
   
   #yiv0826940107 #yiv0826940107photos div label {
   color:#666666;font-size:10px;overflow:hidden;text-align:center;white-space:nowrap;width:64px;}
   
   #yiv0826940107 #yiv0826940107reco-category {
   font-size:77%;}
   
   #yiv0826940107 #yiv0826940107reco-desc {
   font-size:77%;}
   
   #yiv0826940107 .yiv0826940107replbq {
   margin:4px;}
   
   #yiv0826940107 #yiv0826940107ygrp-actbar div a:first-child {
   margin-right:2px;padding-right:5px;}
   
   #yiv0826940107 #yiv0826940107ygrp-mlmsg {
   font-size:13px;font-family:Arial, helvetica, clean,
   sans-serif;}
   
   #yiv0826940107 #yiv0826940107ygrp-mlmsg table {
   font-size:inherit;font:100%;}
   
   #yiv0826940107 #yiv0826940107ygrp-mlmsg select,
   #yiv0826940107 input, #yiv0826940107 textarea {
   font:99% Arial, Helvetica, clean, sans-serif;}
   
   #yiv0826940107 #yiv0826940107ygrp-mlmsg pre, #yiv0826940107
   code {
   font:115% monospace;}
   
   #yiv0826940107 #yiv0826940107ygrp-mlmsg * {
   line-height:1.22em;}
   
   #yiv0826940107 #yiv0826940107ygrp-mlmsg #yiv0826940107logo {
   padding-bottom:10px;}
   
   
   #yiv0826940107 #yiv0826940107ygrp-msg p a {
  
  font-family:Verdana;}
   
   #yiv0826940107 #yiv0826940107ygrp-msg
   p#yiv0826940107attach-count span {
   color:#1E66AE;font-weight:700;}
   
   #yiv0826940107 #yiv0826940107ygrp-reco
   #yiv0826940107reco-head {
   color:#ff7900;font-weight:700;}
   
   #yiv0826940107 #yiv0826940107ygrp-reco {
   margin-bottom:20px;padding:0px;}
   
   #yiv0826940107 #yiv0826940107ygrp-sponsor #yiv0826940107ov
  
  li a {
   font-size:130%;text-decoration:none;}
   
   #yiv0826940107 #yiv0826940107ygrp-sponsor #yiv0826940107ov
   li {
   font-size:77%;list-style-type:square;padding:6px 0;}
   
   #yiv0826940107 #yiv0826940107ygrp-sponsor #yiv0826940107ov
   ul {
   margin:0;padding:0 0 0 8px;}
   
   #yiv0826940107 #yiv0826940107ygrp-text {
   font-family:Georgia;}
   
   #yiv0826940107 #yiv0826940107ygrp-text p {
   margin:0 0 1em 0;}
   
   #yiv0826940107 #yiv0826940107ygrp-text tt {
   font-size:120%;}
   
   #yiv0826940107 #yiv0826940107ygrp-vital ul li:last-child {
   border-right:none !important;
   }
   #yiv0826940107 
   
  
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (2) | 
No comments:
Post a Comment