943,873 Members | Top Members by Rank

Ad:
Mar 7th, 2006
0

getting data from one form to another.

Expand Post »
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub form_activate()
  2. Set m_colSuppID = Nothing
  3. Set m_colSuppID = New Collection
  4.  
  5. strSQL = "SELECT [supplier_ID], [SupplierName] FROM [Supplier]"
  6. With con
  7. .Open
  8. Set RP = .Execute(strSQL)
  9. End With
  10. With RP
  11. lstSupplier.Clear
  12. Do Until .EOF
  13. lstSupplier.AddItem "" & !supplierName
  14. m_colSuppID.Add CStr(!supplier_ID), "" & !SupplierName
  15. .MoveNext
  16. Loop
  17. .Close
  18. End With
  19. con.Close
  20. 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?
Similar Threads
Reputation Points: 13
Solved Threads: 0
Light Poster
skalra63 is offline Offline
30 posts
since Feb 2006
Mar 7th, 2006
1

Re: getting data from one form to another.

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()
Reputation Points: 20
Solved Threads: 10
Junior Poster
aparnesh is offline Offline
193 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: This has to be a simple question to answer.
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: I want to have a nested scrollable area (with buttons and controls) inside a dialog.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC