Resolved Question: VBA programming - Compile error : user-defined type not defined?
I was give the following VBA progam to extract data from DBF file to excel. However, when try to run it, it give me compile error : user-defined type not defined on Public Sub GetCn. Any expert here to advise me what to do ? Is there any add in needed ? If yes, how and what to put in this add in ? Thanks for your help. As I am a dummy to this ADODB process, kindly provide detailed instruction.
Public Sub GetCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)
Set dbcon = New ADODB.Connection
dbcon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile & ";", _
usernm, pword
Set dbrs = New ADODB.Recordset
dbrs.Open sqlstr, dbcon
End Sub
Public Sub getrs()
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
sql = "Select Date, DO_no, QTY from Table1 WHERE DatePart(""m"", Date) = 8 and DatePart(""yyyy"", Date) = 2010"
filenm = "C:\Data\sampledb.mdb"
Call GetCn(adoconn, adors, sql, filenm, "", "")
Dim xlsht As Excel.Worksheet
Set xlsht = Sheets("Sheet1")
xlsht.Range("A1").CopyFromRecordset adors
adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = nothing
End Sub
