Drucker Problem [Printer Object]

Udo

Erfahrenes Mitglied
Hallo Leute!

Ich mache mit dem Printerobject einen Ausdruck --> ist klar!!

Mein Programm beinhaltet so ne art serienbrief, wie man es von MsWord kennt!!

Der Benutzer kann dann seine Empfänger-Andressen aussuchen, die aus einer Datenbank ausgelesen werden!

Dann gehe ich in eine Schleife in der ich die Printer ausgabe mache, und die schleife läuft so lang bis das Recordset-Object End of file ist:

Do Until rs.EOF
Printer.Print rs.fields("Vorname")
usw....
Printer.Enddoc '*** oder so irgendwie heißt das
loop

Ok, ist alles kein problem, er druckt mir das auch so wie ich das haben will, aber mein Windows-Druckprozess bringt mir dann einen Fehler:

****
Die Datei "Der Druckprozess" hat einen Fehler verursacht!
****

Habe keine Ahnung warum dieser Windows-Fehler kommt, hat vielleicht schein einmal das problem gehabt?? Eigentlich ist es kein wirkliches Problem, weil das Programm ja das macht was es tun soll, aber das ist für einen Kunden und es sieht blöd aus wenn da ein fehler kommt!!

Bitte um Hilfe
 
Hi erstmal...

Wenn Du dem Drucker das Enddoc Kommando in der Schleife gibst, druckt der dann nicht bei jedem Durchlauf der Schleife eine neue Seite aus? Nur so'n Gedanke. Ich würde das mal prüfen...

Gruss ITiger.
 
Hi,

ja er beginnt mit jedem Enddoc befehl eine Neue seite, das soll er auch so machen, denn er soll für jede Empfängeradresse die er ausgewählt hat einen eigenen Brief generieren!!
 
Wieviele willst Du denn auf einmal drucken?

Vielleicht tuts ja ein Wait nach einem Druckvorgang (oder nach 10)...

Könnte sein, dass er einfach ZUVIEL drucken soll, und er kann nicht so viele Aufträge auf einmal in die Warteschlange schicken...

Naja, eigentlich hab ich keine Ahnung, aber ich wollte halt versuchen zu helfen, da asphyxia ja scheinbar nicht da ist :)

Gruss ITiger.
 
Hab auch schon gemerkt das asphyxia nicht da ist, weil sonst hätte er schonlange seinen kommentar dazu abgegeben!!

Zum Problem:

Danke für deine Hilfe!!!

Der Fehler kommt sobald ich mehr als einen Druck auftrag in die Warteschleife setzte also ab 2 Druckaufträge kommt der Fehler!!

Wie ist das mit dem Wait, was macht das und wie implementiere ich das genau??

THX Udo
 
schön, dass ihr mich vermisst. =)

zum thema:
wie sieht denn der gesamte code aus und was sagt der debugger dazu? möglicherweise kriegt das drucker-objekt kleine probleme, wenn mehr als zwei seiten direkt hintereinander gedruckt werden sollen.
 
Code:
Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Const WAIT_ABANDONED& = &H80&
Private Const WAIT_ABANDONED_0& = &H80&
Private Const WAIT_FAILED& = -1&
Private Const WAIT_IO_COMPLETION& = &HC0&
Private Const WAIT_OBJECT_0& = 0
Private Const WAIT_OBJECT_1& = 1
Private Const WAIT_TIMEOUT& = &H102&

Private Const INFINITE = &HFFFF
Private Const ERROR_ALREADY_EXISTS = 183&

Private Const QS_HOTKEY& = &H80
Private Const QS_KEY& = &H1
Private Const QS_MOUSEBUTTON& = &H4
Private Const QS_MOUSEMOVE& = &H2
Private Const QS_PAINT& = &H20
Private Const QS_POSTMESSAGE& = &H8
Private Const QS_SENDMESSAGE& = &H40
Private Const QS_TIMER& = &H10
Private Const QS_MOUSE& = (QS_MOUSEMOVE _
                            Or QS_MOUSEBUTTON)
Private Const QS_INPUT& = (QS_MOUSE _
                            Or QS_KEY)
Private Const QS_ALLEVENTS& = (QS_INPUT _
                            Or QS_POSTMESSAGE _
                            Or QS_TIMER _
                            Or QS_PAINT _
                            Or QS_HOTKEY)
Private Const QS_ALLINPUT& = (QS_SENDMESSAGE _
                            Or QS_PAINT _
                            Or QS_TIMER _
                            Or QS_POSTMESSAGE _
                            Or QS_MOUSEBUTTON _
                            Or QS_MOUSEMOVE _
                            Or QS_HOTKEY _
                            Or QS_KEY)

Private Declare Function CreateWaitableTimer Lib "kernel32" _
    Alias "CreateWaitableTimerA" ( _
    ByVal lpSemaphoreAttributes As Long, _
    ByVal bManualReset As Long, _
    ByVal lpName As String) As Long
    
Private Declare Function OpenWaitableTimer Lib "kernel32" _
    Alias "OpenWaitableTimerA" ( _
    ByVal dwDesiredAccess As Long, _
    ByVal bInheritHandle As Long, _
    ByVal lpName As String) As Long
    
Private Declare Function SetWaitableTimer Lib "kernel32" ( _
    ByVal hTimer As Long, _
    lpDueTime As FILETIME, _
    ByVal lPeriod As Long, _
    ByVal pfnCompletionRoutine As Long, _
    ByVal lpArgToCompletionRoutine As Long, _
    ByVal fResume As Long) As Long
    
Private Declare Function CancelWaitableTimer Lib "kernel32" ( _
    ByVal hTimer As Long)
    
Private Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long) As Long
    
Private Declare Function WaitForSingleObject Lib "kernel32" ( _
    ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) As Long
    
Private Declare Function MsgWaitForMultipleObjects Lib "user32" ( _
    ByVal nCount As Long, _
    pHandles As Long, _
    ByVal fWaitAll As Long, _
    ByVal dwMilliseconds As Long, _
    ByVal dwWakeMask As Long) As Long

Public Sub Wait(lNumberOfSeconds As Long)
    Dim ft As FILETIME
    Dim lBusy As Long
    Dim lRet As Long
    Dim dblDelay As Double
    Dim dblDelayLow As Double
    Dim dblUnits As Double
    Dim hTimer As Long
    
    hTimer = CreateWaitableTimer(0, True, App.EXEName & "Timer")
    
    If Err.LastDllError = ERROR_ALREADY_EXISTS Then
        ' If the timer already exists, it does not hurt to open it
        ' as long as the person who is trying to open it has the
        ' proper access rights.
    Else
        ft.dwLowDateTime = -1
        ft.dwHighDateTime = -1
        lRet = SetWaitableTimer(hTimer, ft, 0, 0, 0, 0)
    End If
    
    ' Convert the Units to nanoseconds.
    dblUnits = CDbl(&H10000) * CDbl(&H10000)
    dblDelay = CDbl(lNumberOfSeconds) * 1000 * 10000
    
    ' By setting the high/low time to a negative number, it tells
    ' the Wait (in SetWaitableTimer) to use an offset time as
    ' opposed to a hardcoded time. If it were positive, it would
    ' try to convert the value to GMT.
    ft.dwHighDateTime = -CLng(dblDelay / dblUnits) - 1
    dblDelayLow = -dblUnits * (dblDelay / dblUnits - _
        Fix(dblDelay / dblUnits))
    
    If dblDelayLow < CDbl(&H80000000) Then
        ' &H80000000 is MAX_LONG, so you are just making sure
        ' that you don't overflow when you try to stick it into
        ' the FILETIME structure.
        dblDelayLow = dblUnits + dblDelayLow
    End If
    
    ft.dwLowDateTime = CLng(dblDelayLow)
    lRet = SetWaitableTimer(hTimer, ft, 0, 0, 0, False)
    
    Do
        ' QS_ALLINPUT means that MsgWaitForMultipleObjects will
        ' return every time the thread in which it is running gets
        ' a message. If you wanted to handle messages in here you could,
        ' but by calling Doevents you are letting DefWindowProc
        ' do its normal windows message handling---Like DDE, etc.
        lBusy = MsgWaitForMultipleObjects(1, hTimer, False, _
            INFINITE, QS_ALLINPUT&)
        DoEvents
    Loop Until lBusy = WAIT_OBJECT_0
    
    ' Close the handles when you are done with them.
    CloseHandle hTimer

End Sub

Kopiere das einfach in ein Modul, und rufe die Funktion auf über Wait(Sekunden) also Wait(5) ist eine Pause von 5 Sekunden.

Ich weiss zwar nicht obs was bringt, aber versuchs mal.

Der Code ist nicht von mir...

Gruss ITiger.
 
Zuletzt bearbeitet:
Hallo Leute, danke für eure Hilfe!!!

Mir ist es jetzt etwas peinlich, habe keine probleme mit dem VB-Proggi gehabt sondern mit meinem Drucker selbst, hab ihn neu installed und alles hat funktioniert!!!

Danke trotzdem für eure mühe!!

THX Udo
 
Zurück