jenn5175 Posted August 1, 2003 Posted August 1, 2003 Hey - this may be a simple one, I just haven't done it so I'm not sure of the syntax. I have a tabbed application. Two of the tabs have a similar combobox - a list of all shipments for the day. The comboboxes are populated from a SQL server db. I have one function to populate one of the boxes, and now that I've added a second box I would like to reuse the function to populate that one. However inside the function I have to reference the combobox - how can I vary this depending on which combobox I want to populate/update? Here's my populating function - can someone help me revise it so it makes no hardcoded references to any one control? Public Sub Build_ShipmentCBO(ByVal iShipSelectedID) '*** Initialize Stuff iShipSelectedIndex = 0 i = 1 cboShipments.Items.Clear() ObjConn.Open() ObjSQLCmd.Connection = ObjConn '*** Get Record Count for redim-ing object sSQL = "SELECT count(*) FROM tShipments WHERE iEventID=" & eventItems(cboEvents.SelectedIndex - 1).ID ObjSQLCmd.CommandText = sSQL iRecordCount = ObjSQLCmd.ExecuteScalar() '*** Select all shipments for event and put into record set sSQL = "SELECT iShipmentID, sShipDesc FROM tShipments WHERE iEventID=" & eventItems(cboEvents.SelectedIndex - 1).ID & " ORDER BY sShipDesc" ObjSQLCmd.CommandText = sSQL ObjReader = ObjSQLCmd.ExecuteReader '*** Redim object to size it needs to be ReDim shipmentItems(iRecordCount + 1) '*** Make first entry always be "Choose" shipmentItems(0) = New Class1 shipmentItems(0).Text = "Choose Shipment" shipmentItems(0).ID = 0 cboShipments.Items.Add(shipmentItems(0)) '*** NEED TO CHANGE THIS LINE While ObjReader.Read() '*** Instantiate our item object and fill it with useful information. shipmentItems(i) = New Class1 shipmentItems(i).Text = ObjReader("sShipDesc").ToString shipmentItems(i).ID = ObjReader("iShipmentID") If ObjReader("iShipmentID") = iShipSelectedID Then iShipSelectedIndex = i End If cboShipments.Items.Add(shipmentItems(i)) '*** NEED TO CHANGE THIS i = i + 1 End While ObjReader.Close() ObjConn.Close() cboShipments.SelectedIndex = iShipSelectedIndex '*** NEED TO CHANGE THIS End Sub Thanks Jenn Quote
*Experts* mutant Posted August 1, 2003 *Experts* Posted August 1, 2003 Make your sub accept another argument of the ComboBox type: Public Sub Build_ShipmentCBO(ByVal iShipSelectedID ,ByVal ComboB As ComboBox) Then pass in the instance of the ComboBox you want to modify to the function. Then in your function simply change the occurences of your hardcoded name with the name that you accept, in this example ComboB. Quote
jenn5175 Posted August 1, 2003 Author Posted August 1, 2003 Thanks - I knew there was a simple answer! Jenn Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.