Results 1 to 15 of 15
  1. #1
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

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

  2. #2
    Star Lounger
    Join Date
    Nov 2001
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  3. #3
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    = ClassicTicket()
    Thats what I've put in the on click event row of the property, but that doesn't seem to work.
    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

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

    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.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

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

    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.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Thanx alot Rory,
    That works fine!
    <img src=/S/kiss.gif border=0 alt=kiss width=34 height=15> & a <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

  8. #8
    Star Lounger
    Join Date
    Nov 2001
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  9. #9
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.
    <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  10. #10
    Star Lounger
    Join Date
    Nov 2001
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

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

    Jack

  11. #11
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

  12. #12
    Star Lounger
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  13. #13
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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 <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  14. #14
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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 <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

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

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

    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.
    Charlotte

Posting Permissions

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