• run code from form or access?? (Access 2k)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » run code from form or access?? (Access 2k)

    Author
    Topic
    #364433

    How can I run code from a form or a macro???

    Viewing 1 reply thread
    Author
    Replies
    • #559423

      If you want to call your function from the On Click event of a command button you would put something similar to this in the On Click event: =YourFunctionName(Arguments).

      I haven’t used macros for years so I am not sure how to do what you want.

      hth,
      Jack

      • #559995

        = ClassicTicket()
        Thats what I’ve put in the on click event row of the property, but that doesn’t seem to work.
        confused

        • #560004

          Hi,
          Is your code a function or a procedure? If it’s a sub, you need to click the ellipsis button on the right of the event procedure box, choose Code Builder and then call the sub from the event procedure code that is produced.
          Hope that helps.

          • #560013

            Hi Rory!
            Thanx for the reply but how do I call a procedure?? is it = name of procedure coz thats not working.
            PS: its a sub

            • #560023

              No, that only works with functions. The code builder should give you something like:

              Private Sub Command0_Click()

              End Sub
              and then within the sub you add the line:
              Call ClassicTicket

              Hope that helps.

            • #560024

              Thanx alot Rory,
              That works fine!
              kiss & a bow

        • #560042

          I guess we would need to see the code in your Module or tell us what the code is supposed to do. My suggestion is just one way to call code and may not be the correct way in your case.

          Jack

          • #560047

            Thanx Jack!
            I thought I had to put = followed by the function name and thats why it didn’t work for me when I tried it but it works now when I use Call followed by the function name without the brackets.
            smile

            • #560048

              I am glad you got it to work as that is all that really matters. Continued success!

              Jack

            • #560050

              bow

            • #560225

              FYI: (from the Access Helpfiles on “Call”)

              You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function’s return value is discarded.

              To pass a whole array to a procedure, use the array name followed by empty parentheses.

              HTH thumbup

            • #560245

              Guys, Thank you!
              I used Call followed by the name of the module and it works. All that matters is that it works.
              thank you bow

            • #560282

              Princess, modules are containers that hold routines (procedures)–Subs and Functions. You’ll confuse yourself and the rest of us if you refer to procedures as modules.

    • #560111

      From a macro, the Action is RunCode — but don’t use it. Access macros are evil — unless you wish to create work for consultants like me.

      From code, simply name the sub or function, and include the parameters, if any:
      x = padleft(str, 5, “0”) for instance for a function, or
      msgbox “this is a mesage” for a sub call

      If this is not specific enough, tell me about the code you wish to call.

    Viewing 1 reply thread
    Reply To: run code from form or access?? (Access 2k)

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

    Your information: