BookmarkSubscribeRSS Feed
MikeTurner
Calcite | Level 5

Hi,

I'm trying to read a sas dataset using vba. Below is my codes. But it seems something wrong with my codes or some problems with my seeting.   "Error 424" always pops up. Anyone could help me out?

Thanks in advance.

Public Sub GetData()

Dim obConnection As Object

Dim obRecordset As Object

Dim i As Integer

Set obConnection = CreateObject("Adodb.Connection")

Set obRecordset = CreateObject("ADODB.Recordset")

obConnection.Provider = "sas.LocalProvider.1"

obConnection.Properties("Data Source") = "D:\Project\"

obConnection.Open

obRecordset.Open "raw", obConnection, adOpenStatic, adLockReadOnly, ADODB.adCmdTableDirect

'obRecordset.Open "select * from raw", obConnection, adOpenStatic, adLockReadOnly, ADODB.adCmdTableDirect

Range(Cells(1, 1), Cells(obRecordset.RecordCount + 1, obRecordset.Fields.Count)).NumberFormat = "@"

Cells(1, 1).Select

For i = 0 To obRecordset.Fields.Count - 1

       ActiveCell.Offset(0, i).Value = obRecordset.Fields(i).Name

  Next i

Set obConnection = Nothing

Set obRecordset = Nothing

End Sub

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Discussion stats
  • 0 replies
  • 716 views
  • 0 likes
  • 1 in conversation