Hi Vittorio
Assuming you have the IDs listed in col A of Sheet1 starting from A2 then you need to build up a string to hold the various IDs. Do this first by extrcating the IDs into a variant array:
Dim vIDs As Variant
With Sheets("Sheet1")
vIDs = .Range("A2:A" & .Cells(.Rows.Count,"A").End(xlUp).Row).Value
End With
Next we need to convert this variant array of IDs into a string of IDs bounded by single-quotes and commas:
Dim strIDs As String
strIDs = Join(Application.WorksheetFunction.Transpose(vIDs),"','")
'add the first ' and last ':
strIDs = "'" & strIDs & "'"
Now you have your list, you need to incorporate into your SQL string. The SQL operator IN is the one you want to use, as you have multiple values:
rsOra.Open "Select ID, FIRST_NAME, LAST_NAME from EMPLOYEE Where ID In(" & strIDs & ") ", cnOra, adOpenForwardOnly
Note that I think there is an upper limit to how longg strings can be when using the Open method of the Recordset object (with ADO). If you do run into this barrier, you can get around it, I believe) by using the ADO command object.
Another thing is I have assumed your IDs are textual above - if this is not the case and they are simply numeric numbers then you probably won't need the singlwe quotes around all the values.
Richard
Bookmarks