Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send each item in combo box to update query 1

Status
Not open for further replies.

SuperDuperNuker

Technical User
Apr 3, 2006
6
US
Hi, I have a list of items based on a query and that list is in a combo box. I currently have to select each item in the list and submit it to the update query for processing.
I need to know how to do this programatically.

Something like
Start loop
read item in combo box (query result)
send item as a parameter to another update query
read next item
end loop

please help.......
 
Why a combo box? Use a list box...

Dim vItem as variant, s

For Each vItem In Me!lstBox.ItemsSelected
s = s & lstBox.ItemData(vItem) & ";"
Next
 
I would need to see your update query to answer the second part of sending the value to the query. Not sure what you are trying to do. Here is an example how you can loop through the items in a combo box.
Code:
Private Sub Combo0_DblClick(Cancel As Integer)
  Const intColumn = 1 'The column you want out of the list.  
                      'Zero indexed
  Dim intRow As Integer
  Dim theValue As String '
  For intRow = 0 To (Combo0.listCount - 1)
    theValue = Combo0.Column(intColumn, intRow)
    'Debug.Print theValue 'Error check
    'Code to send theValue to query
  Next intRow
End Sub
 
Thanks MajP that worked great. Now I need to know how to do on a more general basis, where the list of items is just the results of a basic selection query and not in a combo box. I am sorry, but I am new to VBA.
 
My example below uses DAO (data access Objects) and dot notation. This could be done using ADO(Active X Data objects) and bang notation or some combination. The only reason I mention that is that you may see the same thing done a different way, but look very different.
Code:
dim RS as dao.recordset
dim strFieldName as string
dim myValue as string 'double,interger or whatever is in the field
 
set RS = currentdb.openrecordset("theNameOfYourQuery")
strFieldName = "theNameOfYourField"
do while not RS.EOF  'EOF End of File
  myValue = RS.fields(strFieldName)
  'your Code Here using the value you returned from the field
  RS.movenext 'move to next record in the recordset
loop

instead of the name of a query or table you can also put a sql string in the openrecordset
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top