Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Too many labels (Access 2003/SP 1)

    Private Sub Print_Labels_Button_Click()
    On Error GoTo Err_Print_Labels_Button_Click
    I have a button on my form that when clicked will print a label for the current record. Here is the code for it. It worked until I needed to put code in to hide the 'Country' control where the country is 'USA'. I got that to work, but it wants to print all the records now instead of just the current record. Here is the code.

    Dim stDocName As String

    DoCmd.OpenReport "Ship Label", acNormal, , _
    "OrderID=" & Me.OrderID


    Exit_Print_Labels_Button_Click:
    Exit Sub

    Err_Print_Labels_Button_Click:
    MsgBox Err.Description
    Resume Exit_Print_Labels_Button_Click

    End Sub

    This is the code that made it print all records.

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Me.ShipCountry = "USA" Then
    Me.ShipCountry.Visible = False
    Else: Me.ShipCountry.Visible = True
    End If
    End Sub

    I also tried this code and nothing printed then.

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    If Me.ShipCountry = "USA" Then
    Me.ShipCountry.Visible = False
    ElseIf Me.ShipCountry = Not "USA" Then
    Me.ShipCountry.Visible = True
    End If
    End Sub

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

    Re: Too many labels (Access 2003/SP 1)

    There must be something else causing this. Setting a control to visible or invisible shouldn't make any difference as to which records are displayed. Could you post a stripped down and zipped copy of the database?

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Too many labels (Access 2003/SP 1)

    Here it is.

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

    Re: Too many labels (Access 2003/SP 1)

    It works correctly for me with the original code - only the label for the current record on the form is printed.
    The code you tried later doesn't work because the line

    ElseIf Me.ShipCountry = Not "USA" Then

    is not correct. You could use

    ElseIf Not Me.ShipCountry = "USA" Then

    or

    ElseIf Me.ShipCountry <> "USA" Then

    but the ElseIf isn't necessary - or shouldn't be. I have no idea why it doesn't work correctly for you.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Moundridge, Kansas, USA
    Posts
    342
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Too many labels (Access 2003/SP 1)

    Let my try again.

    I tried it again and it works now. The first time I did it, when printing a record with a foreign country, it wanted to print all the labels. Must have been some fluke because it works correctly now.

Posting Permissions

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