Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print a Single Label (A2K)

    It's always the simple ones that stop you. Basically, want to print a single label for the current record. If someone's finished their holiday shopping and has a moment to look at my problem, it would be appreciated.

    Andy
    Cheers,
    Andy

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print a Single Label (A2K)

    I assume that you have already created a label report, let's say rptLabels. We're going to open it using DoCmd.OpenReport and use the WhereCondition argument to limit the report to the current record on your form. You will need a unique identifier for your record, some kind of ID field. Let's be imaginative and say that this field is called, umm, ID. OK?

    Put a command button on your form, with caption "Label" and named cmdLabel. Create the following On Click event procedure for the button:

    Private Sub cmdLabel_Click()
    DoCmd.OpenReport "rptLabels", acViewPreview, , "[ID] = " & Me.[ID]
    End Sub

    I assumed that ID is a numeric field. If it is a text field, you must put quotes before and after the value; we use Chr(34) for this:

    ..., "[ID] = " & Chr(34) & Me.[ID] & Chr(34)

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print a Single Label (A2K)

    Hans,

    As always, you come thru in the clutch. Unfortunately, I can't even try your solution, which I'm sure will work, until tomorrow, because apparently I have to go out and party tonight. Bummer! I mean, what could be more fun than exploring an Access solution. Thanks again, and will get back to you tomorrow.

    Andy
    Cheers,
    Andy

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print a Single Label (A2K)

    Life is hard, sometimes <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Print a Single Label (A2K)

    Good morning, Hans! Your response to Andy answered a question that's been in the back of my mind for some time, and I could hardly wait to try it out today. Sadly, I keep getting a compile error: "Label not defined." I've checked my code many times and fixed a few things I'd overlooked, but the error still keeps popping up. Here's my code:

    Private Sub cmdLabel_Click()
    On Error GoTo Err_cmdLabel_Click

    DoCmd.OpenReport "Labels for Learning Stations", acViewPreview, , "[StationNbr]=" & Me.[StationNbr]
    End Sub

    Exit_cmdLabel_Click:
    Exit Sub

    Err_cmdLabel_Click:
    MsgBox Err.Description
    Resume Exit_cmdLabel_Click

    The field StationNbr is an AutoNumber field. The report "Labels for Learning Stations" gets its data from a query. The query lets me use a parameter to narrow the list of labels. (The report, "Learning Station Labels," prints labels to apply to the monitors of our "learning stations" in two learning labs, which we call "East" and "West." When I launch the report or the form, I get a parameter box that asks me which lab I want to print labels for. I don't know whether this information has any bearing on the compile error.)

    What, pray tell, have I overlooked?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print a Single Label (A2K)

    You've got an End Sub in the wrong place. It should be at the end of the code you posted, below Resume ..., not above Exit_cmdLabel_Click:

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Print a Single Label (A2K)

    Doh! <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

    OK

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print a Single Label (A2K)

    Lucas,

    The following is adapted from a MSKB article that also shows how to specify the number of copies of each label to be printed. Put the following code in a standard module:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Public intLabelBlanks As Integer
    Public intBlankCount As Integer

    ' The following function is run when the report opens.
    ' It displays an inputbox to ask the user how many used
    ' labels to skip.

    Public Function LabelSetup()
    intLabelBlanks = Val(InputBox$("Enter Number of blank labels to skip"))
    If intLabelBlanks < 0 Then
    intLabelBlanks = 0
    End If
    intBlankCount = 0
    End Function

    ' The following function allows the labels to print as the user desires.

    Public Function LabelLayout(R As Report)
    If intBlankCount < intLabelBlanks Then
    R.NextRecord = False
    R.PrintSection = False
    intBlankCount = intBlankCount + 1
    End If
    End Function

    <img src=/w3timages/blueline.gif width=33% height=2>

    Open the label report in design view. Activate the Event tab of the Properties window.
    Enter the following in the On Open event of the report: =LabelSetup() then press Enter.
    Next, click the gray bar at the top of the Detail section.
    Enter the following in the On Print event of the Detail section: =LabelLayout([Report]) then press Enter.

    Make sure that the report has been set up to print the labels across, then down (in the Columns tab of File | Page Setup...)
    Save the report.

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Print a Single Label (A2K)

    Incredible, Hans! This thing works...well, sorta. Just one little hitch.

    The box pops up asking how many labels to skip

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print a Single Label (A2K)

    Lucas, I'll look into it, but I don't have time just now.

  11. #11
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print a Single Label (A2K)

    Good Sunshiny Morning Hans & Lucas,

    Firstly, Hans, as I expected, your routine worked perfectly. Thank You. Now, Lucas, if you want to go to a site at http://www.peterssoftware.com, you'll find a freeware program called LabelSaver that I've tried and used and works perfectly. Instead of asking you how many to skip, it asks you which label you want to start at and also the number of labels you might want to print. You and I are lucky that there are folks like Hans and Peter that are so gracious in sharing their knowledge. I hope this small suggestion of the site to go to is of some help to you,

    Seasons Greetings to all,

    Andy
    Cheers,
    Andy

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print a Single Label (A2K)

    Hi Lucas,

    Back again. I forgot the routine to initialize the intBlankCount variable. Sorry about that. Add the following function to the module:

    Public Function LabelInitialize()
    intBlankCount = 0
    End Function

    You will need to call this in the On Format event of the report header section. If you don't have the report header now, turn it on using View | Report Header and Footer. You can set the height of the report header and footer to 0 if you wish. Select the grey bar at the top of the report header. Enter the following in the On Format event: =LabelInitialize() then press Enter.

  13. #13
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Print a Single Label (A2K)

    You bet it's helpful! Thanks a million!

    This is the kind of help that keeps me coming back almost every day. I've found no other site like it!

  14. #14
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Print a Single Label (A2K)

    Bingo! Now it works!

    Hans, thank you every so much for your help! There's no way I can measure how valuable your help has been to me! Furthermore, other members of my team who have never heard of you or the Lounge owe you a debt of gratitude. And I'll extend all the above to everyone else who contributes to this wonderful resource.

    Happy Holidays to one and all!

  15. #15
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print a Single Label (A2K)

    Hi Andy

    There are db examples at:

    http://www.RogersAccessLibrary.com
    HTH

    John

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •