[VBA] Variable objet ou (...) non définie

Résolu/Fermé
Karuyo - Modifié par Karuyo le 3/05/2011 à 10:54
 Karuyo - 3 mai 2011 à 10:57
Bonjour,
Alors voilà, je suis sous access 2003 et je veux creer une liste pour pouvoir choisir sur quelle imprimante sortir mon état.

Le problème c'est que lorsque je clic sur mon bouton qui est sensé faire le changement d'imprimante et imprimer, j'obtiens l'erreur "Variable objet ou variable de bloc With non définie"

Voici les parties concernées du code :


 Private Sub Form_Load()   
Dim prt As Printer   
  For Each prt In Application.Printers   
    Imprimantes.AddItem prt.DeviceName   
  Next   
  Imprimantes.Value = Application.Printer.DeviceName   
     
End Sub   

-------------------------------------------------------  

Private Sub Imprimer_Click()   
On Error GoTo Err_Imprimer_Click   
       
    Dim prt As Printer   
    Dim prtdefaut As Printer   
    Dim stDocName As String   
       
    prtdefaut = Application.Printer   
       
    For Each prt In Application.Printers   
      If prt.DeviceName = Imprimantes.Value Then   
        Set Application.Printer = prt   
      End If   
    Next   
       
    stDocName = "EtatImp"   
    DoCmd.OpenReport stDocName, acNormal   
       
    Set Application.Printer = prtdefaut   

Exit_Imprimer_Click:   
    Exit Sub   

Err_Imprimer_Click:   
    MsgBox Err.Description   
    Resume Exit_Imprimer_Click   
       
End Sub   



Merci d'avance pour votre aide.


[EDIT]
Bon, c'est cette ligne qui pose problème en fait :

prtdefaut = Application.Printer
Je ne comprends pas pourquoi :/


1 réponse

Bon bha avec un 'set' devant, ça marche mieux ^_^'
0