• Calling a function from another function

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Calling a function from another function

    Author
    Topic
    #356803

    How to call a function from another function

    I want to put a code in the OnOpen event of an order, that will be
    Triggered only in connection of the function Ftransform.
    The function Ftransform is put in the onClick event in the control
    Of a form.
    For example I have a small function called InvisibleInvoice.
    I want this function to be in the OnOpen event of the report
    And to come into force only when the function Ftransform works.
    So to repeat, how to put the function Invsibibled Invoice and to refer
    To the function Ftransform? Just to explain the function Ftransofrm is opening the report under special conditions.
    I will be grateful to any advice

    Viewing 0 reply threads
    Author
    Replies
    • #528741

      I think you need to explain a bit more. And please include the version of Access you’re working with. Some answers only apply to particular versions.

      First of all, anything you put in the OnOpen event is going to execute when that event triggers. The only way you can NOT execute something in that event is if you wrap it in a conditional statement that checks to see if some condition is met and, if so, calls the function you want to call.

      Under normal circumstances, if you use the result of your FTransform function as the condition, that would give you what you want.

      If FTransform=Whatever Then
        InvisibleInvoice
      End If

      Notice I said “normal”. You appear to be asking how to use the result of a function that opens a report in the report it just opened. And you want to do it in the OnOpen event of that report! That means that you CAN’T refer to the FTransform function within the report that is opened because it will try to open it again each time you call it. And since you want to call it from the OnOpen event, you’re going to have an ugly combination of an endless loop and a million error messages.

      Maybe if you explain more specifically what you’re trying to accomplish and what your functions do and whether they are in the report, on a form or in a public module, someone can help you.

      • #528773

        Thank you very much for your precious advices.I want to express my appreciation of this site since it is niot the first time that i receive very kind and very clever suggestions.
        I want to be a bit more clear with ehat I want to do in order to help me find my mistakes.I want to open a report with a function, and on opening the report I want that
        some actions to be executed with another function.Obviously the first function should be declared as Boolean like
        ==============================
        Public Function f1(args) As Boolean
        DoCmd.OpenReport “R1”, acViewPreview
        End Function
        ===========================
        This function is triggered by the onclick event of a control on a form like this
        ======================
        Private Sub Command472_Click()
        F1 (args)
        End Sub
        ============================
        I want to use another function, which for sake of clarity I have simplified like this
        =========================
        Public Function beepit()
        DoCmd.Beep
        End Function
        ==========================
        And I want this function to be used in the OnOpen event of a report only when the function f1(args)is used, like this:
        =============================
        Private Sub Report_Open(Cancel As Integer)
        If Fc1(args) = True Then
        Beepit
        End If
        End Sub
        ==========================
        A very elegant solution but I doesn

        • #528848

          Public Function f1(args) As Boolean

          if args=whatever then
          f1=true
          else
          f1=false
          endif

          End Function
          ===========================
          This function is triggered by the onclick event of a control on a form like this
          ======================
          Private Sub Command472_Click()
          DoCmd.OpenReport “R1”, acViewPreview
          End Sub
          ============================

          Public Function beepit()
          DoCmd.Beep
          End Function
          ==========================

          Private Sub Report_Open(Cancel As Integer)
          If F1(args) Then
          Beepit
          End If
          End Sub
          ==========================

    Viewing 0 reply threads
    Reply To: Calling a function from another function

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: