Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set report's OnOpen Event via Fom? (2003)

    God I'm spamming like hell in this forum.. sorry for that <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    the following: rptTest, frmTest

    I want to open rptTest from frmTest with the following criterias:
    OnOpen: =Mod1()
    OnActivate: =Mod2()
    rptTest.Detail.OnPrint: = Mod1(Reports![rptTest])

    I hope there is some way to set those criterias upon opening the report. Instead I could create a second report and set all those criterias in there - but it's always nice to keep the database small!

    Dennis

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Set report's OnOpen Event via Fom? (2003)

    Where do you get the error? And what do LabelSetup, LabelInitialize and LabelLayout actually do and where do they reside? Are they internal to the report or what? Why are you using Run instead of Call?
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set report's OnOpen Event via Fom? (2003)

    Ok I made it work now, but I had to use some workaround.... My code for rptTest looks like this now:
    <pre>Private Sub Report_Activate()
    If OpenArgs = "Select" Then
    Me.OnOpen = LabelInitialize()
    End If
    End Sub

    Private Sub Report_Open(Cancel As Integer)
    If OpenArgs = "Select" Then
    Me.OnOpen = LabelSetup()
    End If
    End Sub</pre>


    The workaround is that the Details.OnPrint is ALWAYS set to "=LabelLayout(Reports!rptTest)".
    That works, but wouldn't it be a nicer solution to set this OnPrint just like the other criterias via code???

    Dennis

  4. #4
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set report's OnOpen Event via Fom? (2003)

    What I tried so far:

    frmTest:
    <pre>DoCmd.OpenReport "rptTest", acViewPreview, , strWhere, , "Select"</pre>


    rptTest:
    <pre>Private Sub Detailbereich_Print(Cancel As Integer, PrintCount As Integer)
    If OpenArgs = "Select" Then
    Run LabelLayout(Berichte!test)
    End If
    End Sub

    Private Sub Report_Activate()
    If OpenArgs = "Select" Then
    Run LabelInitialize()
    End If
    End Sub

    Private Sub Report_Open(Cancel As Integer)
    If OpenArgs = "Select" Then
    Run LabelSetup()
    End If
    End Sub
    </pre>

    --------------------------

    The thing is that I get an error 2517 "Couldn't find the procedure". When I enter the stuff after Run into the usual boxes everything works fine - just like this there's some faux pax...

  5. #5
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set report's OnOpen Event via Fom? (2003)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    The Module Code:
    <pre>Option Compare Database
    Option Explicit

    Dim intLabelBlanks As Integer
    Dim intLabelCopies As Integer
    Dim intBlankCount As Integer
    Dim intCopyCount As Integer

    '================================================= =========
    ' The following function will cause an inputbox to
    ' display when the report is run that prompts the user
    ' for the number of used labels to skip and how many
    ' copies of each label should be printed.
    '================================================= ==========

    Function LabelSetup()
    intLabelBlanks = Val(InputBox$("Enter Number of blank labels to skip"))
    'intLabelCopies = Val(InputBox$("Enter Number of Copies to Print"))
    If intLabelBlanks < 0 Then intLabelBlanks = 0
    If intLabelCopies < 1 Then intLabelCopies = 1
    End Function

    '================================================= ==========
    ' The following function sets the variables to a zero
    '================================================= ==========

    Function LabelInitialize()
    intBlankCount = 0
    intCopyCount = 0
    End Function

    '================================================= ==========
    ' The following function is the main part of this code
    ' that allows the labels to print as the user desires.
    '================================================= ==========

    Function LabelLayout(R As Report)
    If intBlankCount < intLabelBlanks Then
    R.NextRecord = False
    R.PrintSection = False
    intBlankCount = intBlankCount + 1
    Else
    If intCopyCount < (intLabelCopies - 1) Then
    R.NextRecord = False
    intCopyCount = intCopyCount + 1
    Else
    intCopyCount = 0
    End If
    End If
    End Function
    </pre>

    It's the code provided from Microsoft from here: <!mskb=231801>Microsoft Knowledge Base Article 231801<!/mskb>

    Call doesn't work at all. It says: "Object needed". When I use Run, the InputBox inLabelsBlank opens at least, then I get the error.

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

    Re: Set report's OnOpen Event via Fom? (2003)

    Don't use Run, omit it or use Call. And simply pass Me to LabelLayout.

    Private Sub DetailBereich_Print(Cancel As Integer, PrintCount As Integer)
    If OpenArgs = "Select" Then
    LabelLayout Me
    End If
    End Sub

    Private Sub Report_Activate()
    If OpenArgs = "Select" Then
    LabelInitialize
    End If
    End Sub

    Private Sub Report_Open(Cancel As Integer)
    If OpenArgs = "Select" Then
    LabelSetup
    End If
    End Sub

  7. #7
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set report's OnOpen Event via Fom? (2003)

    ur just a reliable source, thanks hans

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

    Re: Set report's OnOpen Event via Fom? (2003)

    Open your report in design view.
    If it doesn't have a report header and footer, select View | Report Header/Footer. You can reduce the height of the header and footer to 0.
    Click on the gray bar labeled Report Header.
    Activate the Event tab of the Properties window.
    Click in the On Format property, and enter or paste the following into it:
    <code>
    =LabelInitialize()
    </code>
    This was originally placed in the On Activate event of the report, but it doesn't work correctly there.

  9. #9
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set report's OnOpen Event via Fom? (2003)

    Edited by HansV to make URLs clickable - see <!help=19>Help 19<!/help>

    BUMP

    Hmm ok I have a problem I didn't see before.

    When printing those labels, those labels just won't get skipped... To see what I mean i attached the microsoft (!) rptsample database (linked to it, cuz it was too big for this forum). Go to "How to Skip Used Mailing Labels and Print Duplicates".
    Enter some numbers there, hit OK and voil

  10. #10
    2 Star Lounger
    Join Date
    Jun 2004
    Location
    L, Schleswig-Holstein, Germany
    Posts
    184
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Set report's OnOpen Event via Fom? (2003)

    thanks a lot - intersting that there's an error in a Microsoft provided sample database... [img]/forums/images/smilies/wink.gif[/img]

    Works like a charm

    Dennis

Posting Permissions

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