I have some code that lists all of the active printers (but does so in msgboxes rather than a list). I have no problem with that functionality. Here is the code below:
If Printers.Count > 0 Then
strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf
For Each prtLoop In Application.Printers
With prtLoop
MsgBox .DeviceName
End With
Next prtLoop
Else
MsgBox "No printers are installed."
End If
While it does what I essentially need it to do I would like it to only popup if the printer that matches a partial of a printer name that is set in the code. For example if I have 3 printers:
Printer ABC 1
Printer ZZ5 2 (copy)
Printer 123
I want there to be an If Then statement probably after the
For Each prtLoop In Application.Printers
portion of the code above that says if the device name is *ABC then it would only popup with "Printer ABC 1" instead of all 3.
I hope this makes sense. Thanks in advance for the help. -Vladimir
Maybe that is what you wanna do ?
If Printers.Count > 0 Then strMsg = "Printers installed: " & Printers.Count & vbCrLf & vbCrLf For Each prtLoop In Application.Printers With prtLoop If InStr(DeviceName, "ABC") Then MsgBox .DeviceName
End If
End With Next prtLoop Else MsgBox "No printers are installed." End If
edit: Access didn't like the If then statement because it was one line, error was coming up with "End If without Block If" error, I moved the MsgBox .DeviceName to its own line and it works.