Results 1 to 6 of 6
  1. #1
    FD90503 is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    3

    Is there a way to pragmatically pass a Public Procedure Name to a Form cmdButton?

    Hi everyone, Newbie Here!

    Within a Form, I have Command Button that calls and executes a Public Procedure:

    Sub cmdButtton_Click()

    MyProcedureName1

    End Sub


    The above works fine, as expected.

    My question is as follows:

    For my application, I have defined many Procedures within a Public Module (e.g., "MyProcedureName1", "MyProcedureName2", ...)
    and would like to know if there is a way to Call any of these Procedures through a single cmd Button by somehow passing
    a Procedure Name (generated programmatically or through a Record Field). In other words, for each record on my Form (...where cmd Button is defined), I would like to execute a specific procedures through a single cmd Button. I trying to avoid having many unnecessary cmd Butttons on my Form.

    So far, I have not been able to find a way to do this. Any help on this would be greatly appreciated.

    Many thanks in advance!

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,117
    I can think of a few ways of doing this but most would probably involve some Select statements or similar. You can check the PK of the record you're in and call the matching procedure right in the Click event of the button, or you could save the procedure name in the record source of the form and pass it as a variable and use Eval() or Run to execute if:
    https://www.access-programmers.co.uk...riable.160567/
    http://www.vbaexpress.com/forum/show...me-as-variable

    Have a look at this thread and sample in post #18, should give you some hints how to achieve what I think you're after:
    https://www.accessforums.net/showthr...=delete+module

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,807
    Seems like a job for an unbound combo rather than trying to decide which procedure to run based on a control that has no data property?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    FD90503 is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    3
    Gicu,
    Thank You Very Much for the WebLinks you Provided! The example shown in the vbaexpress.com Forum clearly demonstrated what I was looking to achieve.

    Below is what I implemented in my Application:

    Private Sub cmdButton_Click()
    Dim strSubName As String

    strSubName = [ProcedureNames]
    Run strSubName

    End Sub

    ... Works like a charm!

    Also, learned a few new tricks from the other Weblinks!

    Thanks again,
    fd90503

  5. #5
    FD90503 is offline Novice
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    3

    Duplicate Post

    Gicu,
    Thank You Very Much for the WebLinks you Provided! The example shown in the vbaexpress.com Forum clearly demonstrated what I was looking to achieve.

    Below is what I implemented in my Application:

    Private Sub cmdButton_Click()
    Dim strSubName As String

    strSubName = [ProcedureNames]
    Run strSubName

    End Sub

    ... Works like a charm!

    Also, learned a few new tricks from the other Weblinks!

    Thanks again,
    fd90503
    Last edited by FD90503; 02-10-2023 at 06:23 PM. Reason: Duplicate Post

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,117
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 33
    Last Post: 09-25-2015, 08:39 AM
  2. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  3. Attach to current form in public procedure
    By bbrazeau in forum Programming
    Replies: 3
    Last Post: 11-27-2012, 12:59 PM
  4. VBA public procedure in a form
    By gg80 in forum Programming
    Replies: 3
    Last Post: 09-12-2010, 04:55 AM
  5. Pass a form property to a procedure
    By trb5016 in forum Programming
    Replies: 2
    Last Post: 02-17-2010, 04:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums