I had an issue getting data beck from a popup form and was assisted with a solution from Stevoni (thanks again). It has led to another problem however. In trying to send data to the popup I have over loaded the constructor to get the new data across. It appears in the debugger however that when the Friends With Events line (line1 below) is hit it triggers the standard constructor and the form is instantiated with the default constructor (no data passed). Here is where the code goes wonky.

(on the Parent Form)
Friend WithEvents CAddress As frmClientAddress

    Sub ShowMyChildForm(ByVal CID As String)

        CAddress = New frmClientAddress(CID)
        CAddress.Show()

    End Sub

When stepping in with the debugger before it reached the first line of the sub it jumps to this part of the child form.

(on the child form) 
  Public Sub New()
        MyBase.New()
        Dim FormAction As String = "Add"
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

And where I want go, from inside the sub, is:

(on the child form)
Public Sub New(ByVal AddressID As String)
        InitializeComponent()
        FormAction = "Edit"
        CAddID = AddressID
    End Sub

Is there a wat to get this to work properly?

I'm in the middle of debugging my current app, so I can't throw together a test to try out your problem, but we can go with the other solution I had mentioned in the previous post of adding handlers.

What events are going to capture from the child form? Once we know that we can add the handlers using the already created event handling procedures.

You'll change your form variable form being a withevents to a private/public/dim (whatever you prefer).

You'll add the following code AddHandler txtBox.TextChanged, AddressOf TextBox_TextChanged , replace the txtBox with the variable name of the form, replacing the TextChanged event with the event you want to handle and replacing the "TextBox_TextChanged" to the procedure that you're going to trap the event with. (The trapping procedure must have an identical signature to the event.)

Do this for each event, and you won't need the variable to be withevents.

How it'll look on your parent form.

(on the Parent Form)
    private CAddress As frmClientAddress

    Sub ShowMyChildForm(ByVal CID As String)

        CAddress = New frmClientAddress(CID)
        AddHandler txtBox.TextChanged, AddressOf TextBox_TextChanged
        ...repeat for each handled event        
        CAddress.Show()


    End Sub

Ok so I can change the code to something like

Friend  CAddress As frmClientAddress

AddHandler txtBox.TextChanged, AddressOf TextBox_TextChanged 
code to handle event
...etc

ok I'll give that ashot & see what I hit.

Thanx!

Ok so I can change the code to something like

Friend  CAddress As frmClientAddress

AddHandler txtBox.TextChanged, AddressOf TextBox_TextChanged 
code to handle event
...etc

ok I'll give that ashot & see what I hit.

Thanx!

Sorry I'm so scatterbrained today.

If you want to give me some of the events you're wanting to trap, I can put together a better example for you, but for the most part, you're on the right track.

I made the change suggested above and it worked as far as not needing the "With Events" part of the "Friend" declaration. Unfortunately that didn't solve the problem. when I step into the code with the debugger it still jumps to the childform.new() sub and loads the form before executing the childform.New(variable) sub that is called shortly thereafter. Anyone know a reason for this? One possible solution would possible be to reload the childform after calling the childform.new(variable) sub but that would mean essentioally making a duplicate of form_load sub and making it public.

Do you use the empty constructor (New()) at all? If it's not inherited or used, get rid of it.

Do you use the empty constructor (New()) at all? If it's not inherited or used, get rid of it.

That'll be next on my list I do have one other Idea i am going to try first. That will work in this case as this particular form would rarely (if ever) be used without passing some form of ID or something to it. Other forms though may need to use both. Of course I could always pass some form of flag that tells the receiver ignore this and go on without it.

For the moment, I have another situation in an ASP app that requires my immediate attention.

I got it. It was a combination of things (that originally appeared unrelated ) that were causing problems, coupled with the inability in the debugger to see all of the values at one point in time. Basically I stripped this down to do only this and only this, then add other code back in and make sure everything still works. The original code you posted didn't have anything to do with the problems.

I hate when that happens, but am glad you were able to find a solution!

commented: Stevoni's suggestios were instrumental in the final solution to my issue. +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.