S
SandyR
I am trying to get records from an SQL database into an excel worksheet using
VBA. I can connect to the database without errors, but I don't get any
records back (recordcount is -1 and BOF and EOF are both true). If I run the
same query in query analyzer, it returns records. Here is my code:
Set CN = New ADODB.Connection
CN.ConnectionString = "DRIVER={SQL
SERVER};SERVER=TAXSVR\MUNIS;DATABASE=mu_live;UID=userid;PWD=password"
strSQL = "select * from pr_earn_history where a_employee_number = 20390 "
' run query to get data into the recordset
CN.Open
Set RST = CN.Execute(strSQL)
Set WS = wb.Worksheets("SHEET1")
WS.Activate
NROWS = wb.Worksheets("SHEET1").Range("B1").End(xlDown).Row
' get the recordset into the worksheet
Set STARTLOC = WS.Cells(NROWS + 1, 1)
STARTLOC.CopyFromRecordset RST
CN.Close
VBA. I can connect to the database without errors, but I don't get any
records back (recordcount is -1 and BOF and EOF are both true). If I run the
same query in query analyzer, it returns records. Here is my code:
Set CN = New ADODB.Connection
CN.ConnectionString = "DRIVER={SQL
SERVER};SERVER=TAXSVR\MUNIS;DATABASE=mu_live;UID=userid;PWD=password"
strSQL = "select * from pr_earn_history where a_employee_number = 20390 "
' run query to get data into the recordset
CN.Open
Set RST = CN.Execute(strSQL)
Set WS = wb.Worksheets("SHEET1")
WS.Activate
NROWS = wb.Worksheets("SHEET1").Range("B1").End(xlDown).Row
' get the recordset into the worksheet
Set STARTLOC = WS.Cells(NROWS + 1, 1)
STARTLOC.CopyFromRecordset RST
CN.Close