How to choose a label template to be used as the default in application (1 Viewer)

Waxmann

New member
Local time
Today, 10:22
Joined
Aug 18, 2020
Messages
26
I wrote an app that scans a barcode and prints to a label printer.

In the beginning, I want to choose which label template/report I want to use from tblReports and set the choice as default until changed by user.
The choice takes place in a frmSetConfig a list box named lstReports that shows all the reports in database

Next open a frmPricePrt where I scan the barcode, and click Print and have it print using the selected template/report (frmSetConfig.lstReports).

This is where I'm lost and could really use some advice.
Do I store frmSetConfig.lstReports as a public variable or to a table or something else? Can I call that variable when I DoCmd.OpenReport "Labels tblScanProd3", acViewNormal

Thanks for reading this
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:22
Joined
Oct 29, 2018
Messages
21,358
Either way... You should be able to use a table or just hard code the printer info. It all depends on your future needs. For example, would you need to change the printer info eventually? If so, how often? If you have to do it, where would you rather change it: table or code? Do you compile your application to ACCDE? If so, changing code might be an extra work. On the other hand, users could accidentally modify the table when you don't want them to.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:22
Joined
Feb 19, 2002
Messages
42,970
You choose the template when you create the label report. After that, you just print the report. The template isn't referenced again.
 

Waxmann

New member
Local time
Today, 10:22
Joined
Aug 18, 2020
Messages
26
Either way... You should be able to use a table or just hard code the printer info. It all depends on your future needs. For example, would you need to change the printer info eventually? If so, how often? If you have to do it, where would you rather change it: table or code? Do you compile your application to ACCDE? If so, changing code might be an extra work. On the other hand, users could accidentally modify the table when you don't want them to.
Currently I have it hard coded, but it will change depending on the label stock size., so yeah I'm thinking a table. I do compile. What do I change to get it to open the report in a tbl?

If Me.txtScan.Value = DLookup("PLU", "dbo_Menuitem", "PLU=" & """" & Me.txtScan.Value & """") Then
DoCmd.OpenQuery "qryScanProd", acNormal ''Check for plu in dbo.menuitem tbl

DoCmd.OpenReport "Labels tblScanProd3", acViewNormal

Me.Requery
Else
MsgBox "Can't Find This UPC Code", 64, "Try Again"
Me.txtScan = ""
Me.txtScan.SetFocus

End If

End Sub

'''''''''Called from form - not working
Public Sub Command2_Click()
Dim mChoice As String
mChoice = lstReports
''MsgBox mChoice
DoCmd.OpenReport "mChoice", acViewNormal
End Sub
 

Waxmann

New member
Local time
Today, 10:22
Joined
Aug 18, 2020
Messages
26
How do I get the report named in PrinterChoice.Exp1 to print see DoCmd.OpenReport "StrMyLab", acViewNormal below?

Private Sub cmdPrtLab_Click()
Dim StrMyLab As String
StrMyLab = "PrinterChoice.Expr1"
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryUpdateMenuItemPrice", acNormal
DoCmd.OpenQuery "qryUpdatetblScanPricePrt", acNormal
'' change label template here
DoCmd.OpenReport "StrMyLab", acViewNormal
''''''DoCmd.OpenReport "Labels tblScanProd3", acViewNormal
''DoCmd.OpenForm "frmPricePrt", acNormal
DoCmd.Close
End Sub
 

Waxmann

New member
Local time
Today, 10:22
Joined
Aug 18, 2020
Messages
26
You choose the template when you create the label report. After that, you just print the report. The template isn't referenced again.
Thanks, I should have used report instead of template, as template is really it's purpose, not its name. :) But what I really need is a way to select the report to be set as a default, to be used later on when printing from other forms. Thanks for your response!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:22
Joined
Feb 19, 2002
Messages
42,970
Select the report as a default for what? Clearly I'm not understanding the problem. Are you saying that you have multiple sources of data and you want to use the same report to print them?

Assuming the column names are all the same, you can change the RecordSource of the report to refer to a different table or query.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:22
Joined
Oct 29, 2018
Messages
21,358
How do I get the report named in PrinterChoice.Exp1 to print see DoCmd.OpenReport "StrMyLab", acViewNormal below?

Private Sub cmdPrtLab_Click()
Dim StrMyLab As String
StrMyLab = "PrinterChoice.Expr1"
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryUpdateMenuItemPrice", acNormal
DoCmd.OpenQuery "qryUpdatetblScanPricePrt", acNormal
'' change label template here
DoCmd.OpenReport "StrMyLab", acViewNormal
''''''DoCmd.OpenReport "Labels tblScanProd3", acViewNormal
''DoCmd.OpenForm "frmPricePrt", acNormal
DoCmd.Close
End Sub
To use a variable for the report's name, you could try something like this:
Code:
Dim strReport As String
strReport = DLookup("ReportName", "ReportsTable","AnyCriteriaHere")
DoCmd.OpenReport strReport
Hope that helps...
 

Waxmann

New member
Local time
Today, 10:22
Joined
Aug 18, 2020
Messages
26
To use a variable for the report's name, you could try something like this:
Code:
Dim strReport As String
strReport = DLookup("ReportName", "ReportsTable","AnyCriteriaHere")
DoCmd.OpenReport strReport
Hope that helps...
That looks GOOD!! Thanks, I'll let you know
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:22
Joined
Oct 29, 2018
Messages
21,358
This fails
Dim strReport As String
STOPS HERE strReport = DLookup("tblPrinterchoice", "SelectPrt", acViewNormal)

''MsgBox strReport
DoCmd.OpenReport strReport
-----------------------------------------
This works
Dim StrMyLab As String
StrMyLab = "[PrinterChoice.SelectPrt]"
''MsgBox StrMyLab
DoCmd.OpenReport [StrMyLab ], acViewNormal
Hi. The DLookup() function has the following syntax. Make sure you adjust it to suit your setup.

DLookup("FieldName", "TableName", "Criteria")
 

Waxmann

New member
Local time
Today, 10:22
Joined
Aug 18, 2020
Messages
26
Dim mChoice As String
mChoice = lstReports
MsgBox mChoice
''DoCmd.OpenReport "mChoice", acViewNormal
DoCmd.OpenQuery "qryPrtChoice", acViewNormal
Hi. The DLookup() function has the following syntax. Make sure you adjust it to suit your setup.

DLookup("FieldName", "TableName", "Criteria")
Thanks, that was it. Really appreciate your help.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:22
Joined
Oct 29, 2018
Messages
21,358
Dim mChoice As String
mChoice = lstReports
MsgBox mChoice
''DoCmd.OpenReport "mChoice", acViewNormal
DoCmd.OpenQuery "qryPrtChoice", acViewNormal

Thanks, that was it. Really appreciate your help.
Glad to hear you got it sorted out. Good luck with your project.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:22
Joined
Feb 19, 2002
Messages
42,970
Opening a query for the user to interact with is extremely dangerous. You have no control over anything. They can add/change/delete at will. NEVER present queries to the user, ALWAYS use a form or report.
 

Users who are viewing this thread

Top Bottom