Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Form Fields in Another Application

Status
Not open for further replies.

rmtiptoes

IS-IT--Management
Mar 30, 2004
55
US
I have a form that autopopulates a barcode number into the form field upon opening the form. The user then selects a button that will will call and print the barcode through another application. I only want to print the field and not the entire record. Will the following work? The other application has all the printing parms set so I do not have to select the printing.


++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Compare Database

Dim MyApp As Object
Dim lblPercentDone As Object

Option Explicit
' The 'WithEvents' keyword specifies that MyDoc will provide events.
Private WithEvents MyDoc As LabelManager2.Document
Private mblnCancel As Boolean

Private Sub Form_Load()
Set MyApp = New LabelManager2.Application
Set MyDoc = MyApp.Documents.Add("My Documents\Mylan\test.lab")
MyApp.EnableEvents = True

End Sub

Private Sub Print_Barcode_Click()
mblnCancel = False
lblPercentDone.Caption = "0%"
lblPercentDone.Refresh

Call MyDoc.LongTask(10, 0.5)

If Not mblnCancel Then lblPercentDone.Caption = 100

End Sub

Private Sub MyDoc_BeginPrinting(ByVal strDocName As String)
On Error GoTo Err_Print_Barcode_Click

Dim strWhere As String
strDocName = MyApp
strWhere = "[Barcode Number]=" & Me![Barcode Number]
DoCmd.PrintOut strDocName, strWhere

Exit_Print_Barcode_Click:
Exit Sub

Err_Print_Barcode_Click:
MsgBox Err.Description
Resume Exit_Print_Barcode_Click

End Sub

Private Sub MyDoc_ProgressPrinting(ByVal Percent As Integer, Cancel As Integer)
lblPercentDone.Caption = CInt(100 * Percent) & "%"
DoEvents
If mblnCancel Then Cancel = True

End Sub

Private Sub Command2_Click()
mblnCancel = True

End Sub


Homer: But every time I learn something new, it pushes out something old! Remember that time I took a home wine-making course and forgot how to drive?
Marge Simpson: That's because you were drunk!
Homer: And how.

 
rmtiptoes,
I don't think this will do what you want. I see a few issues with your MyDoc_BeginPrinting sub:
1) Your sub accepts a string value as an argument - where is this argument being passed? In any event, you immediately override it by assigning MyApp to strDocName.
2) You have earlier declared MyApp as an object, then initialized it as a LabelManager application. In the MyDoc_BeginPrinting sub you then assign it to a string variable. I think this will produce a type mismatch error.
3) I don't think the syntax of your DoCmd.PrintOut statement will work. The arguments are not correct - and in any event will not accomplish what you want (see below). Check the VBA help files for the right syntax.

If your goal is to pass a list of barcodes to the LabelManager program and print them, it looks like you have a good start in the right direction. You've declared and opened an instance of the LabelManager app. But I think you will need to open a recordset that contains the data you want to send (either through a saved query or through code), loop through the recordset to create a list of barcodes, then send and print them. Creating the recordset and getting the data are easily done with Access and VBA functions - but I think you will need to use the functions, methods, and properties that the LabelManager app exposes in order to get the data into LabelManager and force LabelManager to execute its print routine. You may have to get cozy with the LabelManager API to do this. In other words, Access cannot force LabelManager to print via a native Access print command - but with VBA code, Access CAN open LabelManager and use LabelManager's own print command to get the job done. The LabelManager API will have this info. Does that make sense? I apologize if I'm rehashing stuff you already know.

HTH...

Ken S.
 
Thank you so much. Based upon your comments, I will simply let Access open the app and let the user print the barcode from there.

Thanks again

Homer: But every time I learn something new, it pushes out something old! Remember that time I took a home wine-making course and forgot how to drive?
Marge Simpson: That's because you were drunk!
Homer: And how.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top