ADODB Recordset not working

J

jokobe

Why isn't this code working:

Dim con_ls As Object
Dim rs_ls As Object


Set con_ls = Application.CurrentProject.Connection
Set rs_ls = CreateObject("ADODB.Recordset")

rs_ls.Open "Select firmen_name from t_firmen where " & _
" firmen_grenze_unten < = " & ls_nummer & " and " & _
" firmen_grenze_oben > = " & ls_nummer & " )"

Always get an error message:
"This coonnection can not be used. The connection is closed or not valid"
That is a somehow rough translation from german.

jokobe
 
R

RoyVidar

jokobe wrote in message
Why isn't this code working:

Dim con_ls As Object
Dim rs_ls As Object


Set con_ls = Application.CurrentProject.Connection
Set rs_ls = CreateObject("ADODB.Recordset")

rs_ls.Open "Select firmen_name from t_firmen where " & _
" firmen_grenze_unten < = " & ls_nummer & " and " & _
" firmen_grenze_oben > = " & ls_nummer & " )"

Always get an error message:
"This coonnection can not be used. The connection is closed or not valid"
That is a somehow rough translation from german.

jokobe

I can't find the starting parenthesis of your sql, but if you check the
help files on ADO recordsets, you'll need to pass the connection as
the second arguement

rs_ls.Open <sqlstring>, con_ls

then perhaps also add lock/cursortype, if needed
 
Top