getting data from one form to another.

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2006
Posts: 30
Reputation: skalra63 is an unknown quantity at this point 
Solved Threads: 0
skalra63 skalra63 is offline Offline
Light Poster

getting data from one form to another.

 
0
  #1
Mar 7th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 188
Reputation: aparnesh is an unknown quantity at this point 
Solved Threads: 10
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: getting data from one form to another.

 
1
  #2
Mar 7th, 2006
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()
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 5694 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC