Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Print specific text to a specific printer in Access without a report

Hi all,

I'm trying to print a string of text to a specific printer from a Microsoft Access form. I cannot use a report for this task, it must be straight from the form to the printer.  In VB6 I declare the printer as a variable and then do
printer.print "some text"
but can someone please tell me what the VBA equivalent is????

Thanks in advance
0
kbit
Asked:
kbit
1 Solution
 
peter57rCommented:
I don't believe you can do this in VBA.  The .print command I think is specific to the VB printer object.

It's hard to imagine why you can't use a report - perhaps you would like to say why?
0
 
Frosty555Commented:
There's a winapi call called Shell Execute:

Private Const SW_SHOW = 1
Private Declare Function ShellExecute Lib _
              "shell32.dll" Alias "ShellExecuteA" _
              (ByVal hWnd As Long, _
               ByVal lpOperation As String, _
               ByVal lpFile As String, _
               ByVal lpParameters As String, _
               ByVal lpDirectory As String, _
               ByVal nShowCmd As Long) As Long

Which is used to execute commands on files. So long as a file type has a "print" command in explorer you can pass "print" as the command and have it print just as though you right clicked on the file and click print. e.g.

hHandle = ShellExecute(0&, "print", "C:\somedir\somefile.txt", "", "", SW_SHOW)

Soo... you maybe could write out the text you want to a .txt file and then print it? It's a bit of a runaround but I think it would work.
0
 
kbitAuthor Commented:
My reason for not using a report is because the report comes out in gobbledegook! The font is Arial so I dont undersrtand why
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kbitAuthor Commented:
This seems to have worked, just need it to cut the paper next

Private Sub Command205_Click()
Open "COM1" For Output As #1
Print #1, "Ticket valid for this visit only"
Print #1, " "
Print #1, "Member ID: " & MemberID
Print #1, "Name: " & FirstName & " " & LastName
Print #1, "Ticket Date/Time: " & LastUsed
Print #1, "Facility: " & MemberFacility
Print #1, "Membership Type: " & MembershipType
Print #1, "Credits Remaining: " & CreditsRemaining
Close #1

End Sub
0
 
kbitAuthor Commented:
The solution is:
Private Sub PrintTicket_Click()
            Open "COM1" For Output As #1
            Print #1, "Ticket valid for this visit only"
            Print #1, " "
            Print #1, "Member ID: " & MemberID
            Print #1, "Name: " & FirstName & " " & LastName
            Print #1, "Ticket Date/Time: " & LastUsed
            Print #1, "Facility: " & MemberFacility
            Print #1, "Membership Type: " & MembershipType
            Print #1, "Credits Remaining: " & newcredits
            Print #1, vbCrLf
            Print #1, Chr(29) & "V" & Chr(65) & Chr(0) ' Cut paper
            Close #1
End Sub
0
 
Frosty555Commented:
Seems like you solved your own question.

You should post in the community support zone to close your question with refunded points.
(help article: http://www.experts-exchange.com/help.jsp#hi70)


http://www.experts-exchange.com/Community_Support/General/
0
 
modus_operandiCommented:
Closed, 500 points refunded.
modus_operandi
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now