View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Newman Emanouel Newman Emanouel is offline
external usenet poster
 
Posts: 18
Default ado connection sql script select via listbox

Tom

Thanks - Your the best chuck out the rest !!

Regards

Newman

"Newman Emanouel" wrote:

Dear All

I have been struggling with this problem for a while now and need
assistance. I have two list boxs. One with a list of customer id's and I want
the user to select the custid and the second list box to display the addres
information. I have the following code already and it just doesnt work.
Please help

Dim cnn1 As New ADODB.Connection
Dim rst1 As New ADODB.Recordset

cnn1.Open "PROVIDER=SQLOLEDB;" & _
"Server=XXXXXXXX;INITIAL CATALOG=XXXX;Integrated
Security=sspi"
rst1.Open "SELECT CUSTNAME, Address1, address2, City FROM RM00101 where
custnmbr in ('" & ListBox1.Value & "') ;", _
cnn1, adOpenStatic
rst1.MoveFirst
With Me.ListBox2
.Clear
Do
.AddItem rst1![Custnmbr]
.AddItem rst1![CUSTname]
.AddItem rst1![Address1]
.AddItem rst1![Address2]
.AddItem rst1![City]
rst1.MoveNext
Loop Until rst1.EOF
End With