Results 1 to 5 of 5

Thread: Calling a procedure from a UserControl?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    183

    Calling a procedure from a UserControl?

    If I have a UserControl (UsrCtlDate) which contains a textbox (txtDate_D), how do I call a procedure which lies in the active form when the event "txtDate_D.validating" is fired?

    I tried "Form.ActiveForm.Procedure1" which doesn't work. I also tried declaring a string which contains the name of the current active form, and then using If statements with specific Form names (e.g. If CurrentForm = "frmData" then frmData.Procedure1), which also didn't work. Lastly, I tried UserControl.Parent.Procedure1, which also failed.

    How can I call a procedure which lies in the active form from the UserControl?

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Calling a procedure from a UserControl?

    How about you create a new Event in your user control and you fire the event when you need to. Then in your Main form, you create an Event handler for your event and fire your procedure.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    183

    Re: Calling a procedure from a UserControl?

    Sorry, please elaborate? This is what I have currently:

    <UsrCtlDate>

    VB Code:
    1. Private Sub txtDate_D_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtDate_D.Validating
    2.  
    3.         frmData_TextBox1Validated = Module_txtDates_All_Validating(sender, Me, e)        
    4.         [b]'Form.ActiveForm.LabelInfoChange(frmData_LabelChangeIndex)[/b]
    5.     End Sub

    <frmPrint>

    VB Code:
    1. Public Sub LabelInfoChange(ByVal LabelIndex As Integer, Optional ByVal IsDefault As Boolean = False)
    2.  
    3.         '<Stuff to change the label on frmPrint>
    4.  
    5.     End Sub

    <frmData>

    VB Code:
    1. Public Sub LabelInfoChange(ByVal LabelIndex As Integer, Optional ByVal IsDefault As Boolean = False)
    2.  
    3.         '<Stuff to change the label on frmData>
    4.  
    5.     End Sub

    (The bold code is what I want done, but does not work)

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Calling a procedure from a UserControl?

    Add an event to your UserControl:

    VB Code:
    1. Public Event AfterValidated()
    2.  
    3.  
    4.     Private Sub txtDate_D_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtDate_D.Validating
    5.  
    6.         frmData_TextBox1Validated = Module_txtDates_All_Validating(sender, Me, e)
    7.        RaiseEvent AfterValidated()
    8.     End Sub

    Then wherever you have your usercontrol, you now have an AfterValidated event, where you can then call your LabelInfoChange code.

    VB Code:
    1. Private Sub UserControl12_AfterValidated() Handles UserControl12.AfterValidated
    2.         LabelInfoChange(Me.LabelChangeIndex)
    3.     End Sub

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    183

    Re: Calling a procedure from a UserControl?

    Thanks, I think it's working fine now

Posting Permissions

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



Click Here to Expand Forum to Full Width