ขอคำสั่งตรวจสอบระบบปรินท์ Error ด้วยค่ะ
กระทู้เก่าบอร์ด อ.Yeadram

 5,825   8
URL.หัวข้อ / URL
ขอคำสั่งตรวจสอบระบบปรินท์ Error ด้วยค่ะ

เรียนสอบถามอาจารย์ทุกท่านค่ะ

หนูอยากได้โค้ดคำสั่งตรวจสอบสถานะการปรินท์ ว่า
อยู่ในสถานะพร้อมที่จะปรินท์หรือไม่ หากไม่พร้อม เช่น ไม่มีเครื่องปรินท์
หรือ เหตุอะไรก็แล้วแต่ ที่ไม่อาจปรินท์ได้ ก็ให้มีคำเตือนขึ้นมา พร้อมกับระงับการสั่งปรินท์นั้นๆ

ไม่ทราบว่าต้องทำอย่างไรคะ
วันนี้หนูใช้คำสั่ง ให้เปิดไดอะล็อกเครื่องปรินท์ขึ้นมาให้ผู้ใช้เลือกและยืนยันอีกที่ ซึ่งไม่สะดวก เพราะเอกสารมีครั้งละไม่เกิน 2 หน้าเท่านั้น จึงต้องการให้ปรินท์ทันที่สั่ง (หากเครื่องปรินท์พร้อม)

ขอคำแนะนำด้วยค่ะ

8 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R14172
ลองดูที่นี่ครับ มันเป็นของ VB ก็จริง แต่ปรับนิดหน่อยก็ใช้กับ VBA ได้แล้วครับ เช่น
Text1.Text = ก็เปลี่ยนเป็น Text1 = เหมือนเดิม
Timer1 ก็ใช้เป็น Me.TimerInterval ของ Access แทน (เพราะ Access ไม่มี Object Timer เหมือนใน VB)
อะไรประมาณนี้ โค๊ดนี้ปรับง่ายมาก ใช้ได้จริงครับ ลองทำตามเว็บดู แล้วเราจะได้ค่า Status ของปรินท์เตอร์โดยเฉพาะเรื่องของ Print Job ไปใช้ได้

http://support.microsoft.com/kb/202480
2 @R14185
ลองเข้าไปดูแล้วค่ะ มึนตึบไปต่อไม่ถูก จับต้นชนปลายไม่ถูก
มันสูงไปค่ะ หนูยังไต่ไม่ถึง แต่ก็จะพยายามลองค่อยๆศึกษาแกะไปเรื่อยๆนะคะ

ขอบคุณค่ะ
3 @R14188
งั้นไว้คืนนี้ผมว่างๆ (รอดูบอล) ผมค่อยๆเขียนให้ที่ละขั้นแล้วกันครับ ถือเป็นตัวอย่างให้คนสนใจด้วย
4 @R14192
1. สร้างโมดูลใหม่ ใส่โค๊ดดังนี้:

Option Explicit

Public Declare Function lstrcpy Lib "kernel32" _
   Alias "lstrcpyA" _
   (ByVal lpString1 As String, _
   ByVal lpString2 As String) _
   As Long

Public Declare Function OpenPrinter Lib "winspool.drv" _
   Alias "OpenPrinterA" _
   (ByVal pPrinterName As String, _
   phPrinter As Long, _
   pDefault As PRINTER_DEFAULTS) _
   As Long

Public Declare Function GetPrinter Lib "winspool.drv" Alias "GetPrinterA" _
   (ByVal hPrinter As Long, _
   ByVal Level As Long, _
   pPrinter As Byte, _
   ByVal cbBuf As Long, _
   pcbNeeded As Long) _
   As Long

Public Declare Function ClosePrinter Lib "winspool.drv" _
   (ByVal hPrinter As Long) _
   As Long

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
   (Destination As Any, _
   Source As Any, _
   ByVal Length As Long)

Public Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" _
   (ByVal hPrinter As Long, _
   ByVal FirstJob As Long, _
   ByVal NoJobs As Long, _
   ByVal Level As Long, _
   pJob As Byte, _
   ByVal cdBuf As Long, _
   pcbNeeded As Long, _
   pcReturned As Long) _
   As Long
   
' constants for PRINTER_DEFAULTS structure
Public Const PRINTER_ACCESS_USE = &H8
Public Const PRINTER_ACCESS_ADMINISTER = &H4

' constants for DEVMODE structure
Public Const CCHDEVICENAME = 32
Public Const CCHFORMNAME = 32

Public Type PRINTER_DEFAULTS
   pDatatype As String
   pDevMode As Long
   DesiredAccess As Long
End Type

Public Type DEVMODE
   dmDeviceName As String * CCHDEVICENAME
   dmSpecVersion As Integer
   dmDriverVersion As Integer
   dmSize As Integer
   dmDriverExtra As Integer
   dmFields As Long
   dmOrientation As Integer
   dmPaperSize As Integer
   dmPaperLength As Integer
   dmPaperWidth As Integer
   dmScale As Integer
   dmCopies As Integer
   dmDefaultSource As Integer
   dmPrintQuality As Integer
   dmColor As Integer
   dmDuplex As Integer
   dmYResolution As Integer
   dmTTOption As Integer
   dmCollate As Integer
   dmFormName As String * CCHFORMNAME
   dmLogPixels As Integer
   dmBitsPerPel As Long
   dmPelsWidth As Long
   dmPelsHeight As Long
   dmDisplayFlags As Long
   dmDisplayFrequency As Long
End Type

Type SYSTEMTIME
   wYear As Integer
   wMonth As Integer
   wDayOfWeek As Integer
   wDay As Integer
   wHour As Integer
   wMinute As Integer
   wSecond As Integer
   wMilliseconds As Integer
End Type

Type JOB_INFO_2
   JobId As Long
   pPrinterName As Long
   pMachineName As Long
   pUserName As Long
   pDocument As Long
   pNotifyName As Long
   pDatatype As Long
   pPrintProcessor As Long
   pParameters As Long
   pDriverName As Long
   pDevMode As Long
   pStatus As Long
   pSecurityDescriptor As Long
   Status As Long
   Priority As Long
   Position As Long
   StartTime As Long
   UntilTime As Long
   TotalPages As Long
   Size As Long
   Submitted As SYSTEMTIME
   time As Long
   PagesPrinted As Long
End Type

Type PRINTER_INFO_2
   pServerName As Long
   pPrinterName As Long
   pShareName As Long
   pPortName As Long
   pDriverName As Long
   pComment As Long
   pLocation As Long
   pDevMode As Long
   pSepFile As Long
   pPrintProcessor As Long
   pDatatype As Long
   pParameters As Long
   pSecurityDescriptor As Long
   Attributes As Long
   Priority As Long
   DefaultPriority As Long
   StartTime As Long
   UntilTime As Long
   Status As Long
   cJobs As Long
   AveragePPM As Long
End Type

Public Const ERROR_INSUFFICIENT_BUFFER = 122
Public Const PRINTER_STATUS_BUSY = &H200
Public Const PRINTER_STATUS_DOOR_OPEN = &H400000
Public Const PRINTER_STATUS_ERROR = &H2
Public Const PRINTER_STATUS_INITIALIZING = &H8000
Public Const PRINTER_STATUS_IO_ACTIVE = &H100
Public Const PRINTER_STATUS_MANUAL_FEED = &H20
Public Const PRINTER_STATUS_NO_TONER = &H40000
Public Const PRINTER_STATUS_NOT_AVAILABLE = &H1000
Public Const PRINTER_STATUS_OFFLINE = &H80
Public Const PRINTER_STATUS_OUT_OF_MEMORY = &H200000
Public Const PRINTER_STATUS_OUTPUT_BIN_FULL = &H800
Public Const PRINTER_STATUS_PAGE_PUNT = &H80000
Public Const PRINTER_STATUS_PAPER_JAM = &H8
Public Const PRINTER_STATUS_PAPER_OUT = &H10
Public Const PRINTER_STATUS_PAPER_PROBLEM = &H40
Public Const PRINTER_STATUS_PAUSED = &H1
Public Const PRINTER_STATUS_PENDING_DELETION = &H4
Public Const PRINTER_STATUS_PRINTING = &H400
Public Const PRINTER_STATUS_PROCESSING = &H4000
Public Const PRINTER_STATUS_TONER_LOW = &H20000
Public Const PRINTER_STATUS_USER_INTERVENTION = &H100000
Public Const PRINTER_STATUS_WAITING = &H2000
Public Const PRINTER_STATUS_WARMING_UP = &H10000
Public Const JOB_STATUS_PAUSED = &H1
Public Const JOB_STATUS_ERROR = &H2
Public Const JOB_STATUS_DELETING = &H4
Public Const JOB_STATUS_SPOOLING = &H8
Public Const JOB_STATUS_PRINTING = &H10
Public Const JOB_STATUS_OFFLINE = &H20
Public Const JOB_STATUS_PAPEROUT = &H40
Public Const JOB_STATUS_PRINTED = &H80
Public Const JOB_STATUS_DELETED = &H100
Public Const JOB_STATUS_BLOCKED_DEVQ = &H200
Public Const JOB_STATUS_USER_INTERVENTION = &H400
Public Const JOB_STATUS_RESTART = &H800

Public Function GetString(ByVal PtrStr As Long) As String
   Dim StrBuff As String * 256
   
   'Check for zero address
   If PtrStr = 0 Then
      GetString = " "
      Exit Function
   End If
   
   'Copy data from PtrStr to buffer.
   CopyMemory ByVal StrBuff, ByVal PtrStr, 256
   
   'Strip any trailing nulls from string.
   GetString = StripNulls(StrBuff)
End Function

Public Function StripNulls(OriginalStr As String) As String
   'Strip any trailing nulls from input string.
   If (InStr(OriginalStr, Chr(0)) > 0) Then
      OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
   End If

   'Return modified string.
   StripNulls = OriginalStr
End Function

Public Function PtrCtoVbString(Add As Long) As String
    Dim sTemp As String * 512
    Dim x As Long

    x = lstrcpy(sTemp, Add)
    If (InStr(1, sTemp, Chr(0)) = 0) Then
        PtrCtoVbString = ""
    Else
        PtrCtoVbString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1)
    End If
End Function

Public Function CheckPrinterStatus(PI2Status As Long) As String
   Dim tempStr As String
   
   If PI2Status = 0 Then   ' Return "Ready"
      CheckPrinterStatus = "Printer Status = Ready" & vbCrLf
   Else
      tempStr = ""   ' Clear
      If (PI2Status And PRINTER_STATUS_BUSY) Then
        tempStr = tempStr & "Busy "
      End If
      
      If (PI2Status And PRINTER_STATUS_DOOR_OPEN) Then
        tempStr = tempStr & "Printer Door Open "
      End If
      
      If (PI2Status And PRINTER_STATUS_ERROR) Then
        tempStr = tempStr & "Printer Error "
      End If
      
      If (PI2Status And PRINTER_STATUS_INITIALIZING) Then
        tempStr = tempStr & "Initializing "
      End If
      
      If (PI2Status And PRINTER_STATUS_IO_ACTIVE) Then
        tempStr = tempStr & "I/O Active "
      End If

      If (PI2Status And PRINTER_STATUS_MANUAL_FEED) Then
        tempStr = tempStr & "Manual Feed "
      End If
      
      If (PI2Status And PRINTER_STATUS_NO_TONER) Then
        tempStr = tempStr & "No Toner "
      End If
      
      If (PI2Status And PRINTER_STATUS_NOT_AVAILABLE) Then
        tempStr = tempStr & "Not Available "
      End If
      
      If (PI2Status And PRINTER_STATUS_OFFLINE) Then
        tempStr = tempStr & "Off Line "
      End If
      
      If (PI2Status And PRINTER_STATUS_OUT_OF_MEMORY) Then
        tempStr = tempStr & "Out of Memory "
      End If
      
      If (PI2Status And PRINTER_STATUS_OUTPUT_BIN_FULL) Then
        tempStr = tempStr & "Output Bin Full "
      End If
      
      If (PI2Status And PRINTER_STATUS_PAGE_PUNT) Then
        tempStr = tempStr & "Page Punt "
      End If
      
      If (PI2Status And PRINTER_STATUS_PAPER_JAM) Then
        tempStr = tempStr & "Paper Jam "
      End If

      If (PI2Status And PRINTER_STATUS_PAPER_OUT) Then
        tempStr = tempStr & "Paper Out "
      End If
      
      If (PI2Status And PRINTER_STATUS_OUTPUT_BIN_FULL) Then
        tempStr = tempStr & "Output Bin Full "
      End If
      
      If (PI2Status And PRINTER_STATUS_PAPER_PROBLEM) Then
        tempStr = tempStr & "Page Problem "
      End If
      
      If (PI2Status And PRINTER_STATUS_PAUSED) Then
        tempStr = tempStr & "Paused "
      End If

      If (PI2Status And PRINTER_STATUS_PENDING_DELETION) Then
        tempStr = tempStr & "Pending Deletion "
      End If
      
      If (PI2Status And PRINTER_STATUS_PRINTING) Then
        tempStr = tempStr & "Printing "
      End If
      
      If (PI2Status And PRINTER_STATUS_PROCESSING) Then
        tempStr = tempStr & "Processing "
      End If
      
      If (PI2Status And PRINTER_STATUS_TONER_LOW) Then
        tempStr = tempStr & "Toner Low "
      End If

      If (PI2Status And PRINTER_STATUS_USER_INTERVENTION) Then
        tempStr = tempStr & "User Intervention "
      End If
      
      If (PI2Status And PRINTER_STATUS_WAITING) Then
        tempStr = tempStr & "Waiting "
      End If
      
      If (PI2Status And PRINTER_STATUS_WARMING_UP) Then
        tempStr = tempStr & "Warming Up "
      End If
      
      'Did you find a known status?
      If Len(tempStr) = 0 Then
        tempStr = "Unknown Status of " & PI2Status
      End If
      
      'Return the Status
      CheckPrinterStatus = "Printer Status = " & tempStr & vbCrLf
   End If
End Function
5 @R14193
2. ในฟอร์ม สร้าง Object ขึ้นใหม่ดังนี้:
    2.1 สร้าง Text Box ขึ้นใหม่ 3 ตัว ใช้ชื่อเรียงกันคือ Text1, Text2, Text3 กำหนดความยาว,สูง ให้มากเพราะข้อมูลมีหลายบรรทัด
    2.2 สร้าง Button ขึ้นใหม่ 3 ตัว ใช้ชื่อเรียงกันคือ Command1, Command2, Command3

3. ใส่โค๊ดใน Command1 Event > On Click ดังนี้:
'Private Sub Command1_Click()
   'Enable the timer to begin printer status checks.
   Me.TimerInterval = 500
   
   'Enable and disable start and stop buttons.
   Command1.Enabled = False
   Command2.Enabled = True
   Command3.Enabled = True
'End Sub


4. ใส่โค๊ดใน Command2 Event > On Click ดังนี้:
'Private Sub Command2_Click()
   'Disable timer to stop further printer checks.
   Me.TimerInterval = 0
   
   'Enable and disable start and stop buttons.
   Command1.Enabled = True
   Command2.Enabled = False
   Command3.Enabled = True
'End Sub


5. ใส่โค๊ดใน Command3 Event > On Click ดังนี้:
'Private Sub Command3_Click()
   'Clear the status info.
   Text1.Value = ""
   Text2 = ""
   Text3 = ""
'End Sub
6 @R14194
6. ใส่โค๊ดบนฟอร์ม Event > On Load ดังนี้:
'Private Sub Form_Load()
   'Initialize captions for control buttons.
   Command1.Caption = "Start"
   Command2.Caption = "Stop"
   Command3.Caption = "Clear"
   
   'Clear the status info.
   Text1 = ""
   Text2 = ""
   Text3 = ""
   
   Command1.Enabled = True
   'Disable stop and clear buttons.
   Command2.Enabled = False
   Command3.Enabled = False
   
   'Set interval for printer status checking to 1/2 second.
'End Sub


7. เพิ่มฟังก์ชั่นลงในโค๊ด VBA ของฟอร์ม ดังนี้:
'------------------------Start Function------------------------
Public Function CheckPrinter(PrinterStr As String, JobStr As String) As String
   Dim hPrinter As Long
   Dim ByteBuf As Long
   Dim BytesNeeded As Long
   Dim PI2 As PRINTER_INFO_2
   Dim JI2 As JOB_INFO_2
   Dim PrinterInfo() As Byte
   Dim JobInfo() As Byte
   Dim result As Long
   Dim LastError As Long
   Dim PrinterName As String
   Dim tempStr As String
   Dim NumJI2 As Long
   Dim pDefaults As PRINTER_DEFAULTS
   Dim i As Integer

   'Set a default return value if no errors occur.
   CheckPrinter = "Printer info retrieved"
   
   'NOTE: You can pick a printer from the Printers Collection
   'or use the EnumPrinters() API to select a printer name.
   
   'Use the default printer of Printers collection.
   'This is typically, but not always, the system default printer.
   PrinterName = Printer.DeviceName 'can be a network path eg. "\ \MYSERVER\PrinterName"
   'Set desired access security setting.
   pDefaults.DesiredAccess = PRINTER_ACCESS_USE
   
   'Call API to get a handle to the printer.
   result = OpenPrinter(PrinterName, hPrinter, pDefaults)
   If result = 0 Then
      'If an error occurred, display an error and exit sub.
      CheckPrinter = "Cannot open printer " & PrinterName & _
        ", Error: " & Err.LastDllError
      Exit Function
   End If

   'Init BytesNeeded
   BytesNeeded = 0

   'Clear the error object of any errors.
   Err.Clear

   'Determine the buffer size that is needed to get printer info.
   result = GetPrinter(hPrinter, 2, 0&, 0&, BytesNeeded)
   
   'Check for error calling GetPrinter.
   If Err.LastDllError <> ERROR_INSUFFICIENT_BUFFER Then
      'Display an error message, close printer, and exit sub.
      CheckPrinter = " > GetPrinter Failed on initial call! EnumJobs Failed on second call! < Error = " _
            & LastError
        ClosePrinter hPrinter
        Exit Function
      End If
      
      'Copy contents of print job info byte array into a
      'JOB_INFO_2 structure to separate the individual elements.
      For i = 0 To NumJI2 - 1   ' Loop through jobs and walk the buffer
          CopyMemory JI2, JobInfo(i * Len(JI2)), Len(JI2)
             
          ' List info available on Jobs.
          Debug.Print "Job ID" & vbTab & JI2.JobId
          Debug.Print "Name Of Printer" & vbTab & _
            GetString(JI2.pPrinterName)
          Debug.Print "Name Of Machine That Created Job" & vbTab & _
            GetString(JI2.pMachineName)
          Debug.Print "Print Job Owner's Name" & vbTab & _
            GetString(JI2.pUserName)
          Debug.Print "Name Of Document" & vbTab & GetString(JI2.pDocument)
          Debug.Print "Name Of User To Notify" & vbTab & _
            GetString(JI2.pNotifyName)
          Debug.Print "Type Of Data" & vbTab & GetString(JI2.pDatatype)
          Debug.Print "Print Processor" & vbTab & _
            GetString(JI2.pPrintProcessor)
          Debug.Print "Print Processor Parameters" & vbTab & _
            GetString(JI2.pParameters)
          Debug.Print "Print Driver Name" & vbTab & _
            GetString(JI2.pDriverName)
          Debug.Print "Print Job 'P' Status" & vbTab & _
            GetString(JI2.pStatus)
          Debug.Print "Print Job Status" & vbTab & JI2.Status
          Debug.Print "Print Job Priority" & vbTab & JI2.Priority
          Debug.Print "Position in Queue" & vbTab & JI2.Position
          Debug.Print "Earliest Time Job Can Be Printed" & vbTab & _
            JI2.StartTime
          Debug.Print "Latest Time Job Will Be Printed" & vbTab & _
            JI2.UntilTime
          Debug.Print "Total Pages For Entire Job" & vbTab & JI2.TotalPages
          Debug.Print "Size of Job In Bytes" & vbTab & JI2.Size
          'Because of a bug in Windows NT 3.51, the time member is not set correctly.
          'Therefore, do not use the time member on Windows NT 3.51.
          Debug.Print "Elapsed Print Time" & vbTab & JI2.time
          Debug.Print "Pages Printed So Far" & vbTab & JI2.PagesPrinted
             
          'Display basic job status info.
          JobStr = JobStr & "Job ID = " & JI2.JobId & _
             vbCrLf & "Total Pages = " & JI2.TotalPages & vbCrLf
          
          tempStr = ""   'Clear
          'Check for a ready state.
          If JI2.pStatus = 0& Then   ' If pStatus is Null, check Status.
            If JI2.Status = 0 Then
               tempStr = tempStr & "Ready! " & vbCrLf
            Else 'Check for the various print job states.
               If (JI2.Status And JOB_STATUS_SPOOLING) Then
                  tempStr = tempStr & "Spooling "
               End If
              
               If (JI2.Status And JOB_STATUS_OFFLINE) Then
                  tempStr = tempStr & "Off line "
               End If
              
               If (JI2.Status And JOB_STATUS_PAUSED) Then
                  tempStr = tempStr & "Paused "
               End If
              
               If (JI2.Status And JOB_STATUS_ERROR) Then
                  tempStr = tempStr & "Error "
               End If
              
               If (JI2.Status And JOB_STATUS_PAPEROUT) Then
                  tempStr = tempStr & "Paper Out "
               End If
              
               If (JI2.Status And JOB_STATUS_PRINTING) Then
                  tempStr = tempStr & "Printing "
               End If
              
               If (JI2.Status And JOB_STATUS_USER_INTERVENTION) Then
                  tempStr = tempStr & "User Intervention Needed "
               End If
              
               If Len(tempStr) = 0 Then
                  tempStr = "Unknown Status of " & JI2.Status
               End If
            End If
        Else
            ' Dereference pStatus.
            tempStr = PtrCtoVbString(JI2.pStatus)
        End If
          
          'Report the Job status.
          JobStr = JobStr & tempStr & vbCrLf
          Debug.Print JobStr & tempStr
      Next i
   End If
   
   'Close the printer handle.
   ClosePrinter hPrinter
End Function
'-------------------------End Function-------------------------
7 @R14195
8. ใส่โค๊ดบนฟอร์ม Event > On Time ดังนี้:

Private Sub Form_Timer()
   Dim PrinterStatus As String
   Dim JobStatus As String
   Dim ErrorInfo As String
   
   'Clear the status info for new info/status.
   Text1 = ""
   Text2 = ""
   Text3 = ""
   
   'Call sub to perform check.
   Text1 = CheckPrinter(PrinterStatus, JobStatus)
   Text2 = PrinterStatus
   Text3 = JobStatus
End Sub

9. หลังจากการเปิดฟอร์ม กดปุ่ม Start จะมีค่าแสดงใน Text Box ทั้งสาม เพื่อบอกสถานะของ Printer ที่เราเซ็ท Default

- ขณะเครื่องพิมพ์พร้อมพิมพ์ และไม่มี Jobs ใดๆค้างอยู่:

Text1 = Printer info retrieved

Text2 = Printer Status = Ready
        Printer Name = CutePDF Writer
        Printer Driver Name = CutePDF Writer
        Printer Port Name = CPW2:

Text3 = No Print Jobs!

- ขณะเครื่องพิมพ์พร้อมพิมพ์ แต่ยังมี Jobs ที่กำลังพิมพ์ค้างอยู่:

Text1 = Printer info retrieved

Text2 = Printer Status = Ready
        Printer Name = CutePDF Writer
        Printer Driver Name = CutePDF Writer
        Printer Port Name = CPW2:

Text3 = Job ID = 2
        Total Pages = 4
        Spooling Printing
        Job ID = 3
        Total Pages = 5
        Ready!

จากการทดสอบสามารถใช้กับเครื่องพิมพ์ที่ต่อโดยตรง (Local Printer) และเครื่องพิมพ์ที่ต่อแบบเครือข่าย (Network Printer)

โดยการใช้งานคุณอาจทำเป็น Display ดูสถานะ หากที่ Text3 แสดงคำว่า "No Print Jobs!" ก็แสดงว่าเครื่องพิมพ์ว่างอยู่ ไม่มีคิวการพิมพ์ ก็สั่งพิมพ์งานได้เลย
หรือจะสร้างเป็นเงื่อนไขที่ปุ่มสั่งพิมพ์
    Dim PrinterStatus As String, JobStatus As String
    CheckPrinter PrinterStatus, JobStatus
    If JobStatus = "No Print Jobs!" Then
        ' คำสั่งพิมพ์งานได้เลย
       ..........
    Else
        ' เครื่องพิมพ์ไม่ว่าง
    End If

ประมาณนี้ครับ ปรับใช้ดูนะครับ
ปล. โค๊ดตัวอย่างทั้งหมดมาจากทางเว็บ Support ของ Microsoft ตามลิ้งค์ http://support.microsoft.com/kb/202480
8 @R14197
ขอบพระคุณอย่างยิ่งค่ะอาจารย์ TTT กว่าอาจารย์จะเขียนโค้ดนี้เสร็จ ไม่อยากจะจินตนาการเลยค่ะว่าต้องใช้เวลาสมาธิขนาดไหน
เป็นโค้ดที่ยาวมากๆสำหรับหนู แต่อย่างนี้พอไหวค่ะ
พอจะลำดับค่อยๆทำตามได้
หนูจะลองทำตามดูนะคะ ได้ผลอย่างไร จะเข้ามารายงานให้ทราบค่ะอาจารย์
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.3310s