i wondered if anyone could help me with this.

i have a button on a form (frmUpdateProduct). this button opens up another form (frmSelectSupplier). i have a listbox which gets all the supplier names from the access database, and assigns then with the Supplier ID (also from the database). here is the code for the listbox:

Private Sub form_activate()
Set m_colSuppID = Nothing
    Set m_colSuppID = New Collection
    
    strSQL = "SELECT [supplier_ID], [SupplierName] FROM [Supplier]"
    With con
        .Open
        Set RP = .Execute(strSQL)
    End With
    With RP
        lstSupplier.Clear
        Do Until .EOF
            lstSupplier.AddItem "" & !supplierName
            m_colSuppID.Add CStr(!supplier_ID), "" & !SupplierName
            .MoveNext
        Loop
        .Close
    End With
    con.Close
End Sub

i need to get the supplier name/ supplier id, to be sent to a text box (frmUpdateProduct.TxtSupplier.text). how would i do this?

2 ways :

You can have the Supplier data (Name, Id) as global variables. From form1 (SelectSupp) set the values of the globals and then open form2(UpdProduct). Then u can access the global variables from form2. Frankly, some programmers don't like to use globals, so the second method is better.


Declare a public function in form1 that shows the SuppName.
Public ShowSuppName() as String
ShowSuppName = lstSupplier.Text
End Function

Then call this function from form2 after it has been loaded
txtSupplier.text = form1.ShowSuppName()

commented: Thumbs Up Buddy +2
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.