Refresh combo from another form

Cassio

Junior Contributor
Joined
Nov 30, 2002
Messages
276
Location
Rio de Janeiro
Hi! I have a MDI app and I need to refresh a combolist from form1 when I press the update button on form2. I have a Sub to populate the combo, and it works only when I call it from within the form1 code. When I call it from another form it doesnt refresh the combo.
Here´s how im calling this sub:

Visual Basic:
Dim f as new form1()
f.PopulateCombo()

Thanks
 
You created a new instance of form1 on your form2 when you:
Visual Basic:
Dim f as New Form1
thus you will never update your original combo on form1.

Who creates the instance of Form2? The MDI parent or Form1?
A reference to either Form1 or the combobox must be passed into form2 at some point, in order for you to fire your sub.
 
I cant get it right.

I´m starting with a MDI Parent and i´m using this code to open the forms:

Visual Basic:
    Private Sub OpenCompras()
        Dim frmCompras As New Compras()
        frmCompras = New Compras()
        If Not IsOpen(frmCompras) Then
            frmCompras.MdiParent = Me
            frmCompras.Show()
        End If
   End Sub

    Private Sub OpenFornecedores()
        Dim frmForn As New Fornecedores()
        If Not IsOpen(frmForn) Then
            frmForn.MdiParent = Me
            frmForn.Show()
        End If
    End Sub

    Public Function IsOpen(ByVal frm As Form) As Boolean
        Dim ret As Boolean, stdForm As Form
        ret = False

        For Each stdForm In Me.MdiChildren
            If stdForm.Name = frm.Name Then
                stdForm.Focus()
                ret = True
                Exit For
            End If
        Next

        Return ret
    End Function

On the MDI Child Compras form I have this sub:

Visual Basic:
Public Sub PopulateCombo()
        Dim strSQL As String
        Dim objListitem As ListItems
        ' .... the code here is not important

I want to call it from the other MDI Child. Do you have any ideas?
I tried everything.

Thanks.
 
Problem solved.
Just declared the frmCompras (in the MDI Parent) as Public Shared and its Subs and Functions could be accessed from anywhere.
 
Back
Top