Results 1 to 4 of 4
  1. #1
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47

    Pass Form name in the fucntion call

    Hi All

    The below sub is present in a module .This works fine. But how can I change the code so that the form name is passed in the parameters of the procedure as this way the procedure can be called as many times as required from different forms:



    Code:
    Option Compare Database
    Public Sub SendAgent()
    If MsgBox("Do you wish to send this form to " & Forms("frmCoach")!cboAgent.Column(1) & " to sign off") = vbYes Then
    MsgBox "Hello"
    End If
    End Sub
    This sub is called from the click event of a Button:
    Code:
    Private Sub cmdAdd_Click()
    Call SendAgent
    end sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Quote Originally Posted by AmanKaur123 View Post
    Hi All

    Code:
    Option Compare Database
    Public Sub SendAgent(frmName As String)
    If MsgBox("Do you wish to send this form to " & Forms("frmCoach")!cboAgent.Column(1) & " to sign off") = vbYes Then
    MsgBox "Hello"
    End If
    End Sub
    This sub is called from the click event of a Button:
    Code:
    Private Sub cmdAdd_Click()
    Call SendAgent("FormName")
    end sub
    I'd probably pass the cbo value as well, assuming it comes from the form that calls your sub.
    Public Sub SendAgent(frmName As String, cboValue As String)

    Call SendAgent("frmName", Me.cbo) - *handle what to do if cbo is Null* & can't recall if quotes are required for the second parameter. I think not, but I wouldn't try to concatenate them - I'd assign the control value to a variable.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47
    Thanks a million Micron. It worked fine.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You're welcome. Please mark your thread as solved if all is well.

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

Similar Threads

  1. Add wildcards to this FindWords Fucntion?
    By zashaikh in forum Access
    Replies: 3
    Last Post: 02-09-2017, 10:01 AM
  2. Replies: 11
    Last Post: 01-16-2017, 11:46 PM
  3. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  4. Replies: 7
    Last Post: 03-11-2015, 12:48 PM
  5. Using a check box to call a form
    By mrdirectorsir in forum Access
    Replies: 1
    Last Post: 06-02-2014, 05:05 PM

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