N
Neeraj
Hi,
I'm trying to create a function to store the recordset with this
code...
Private Function sOpenExcel(query As String)
' strFilePath = "C:\myfile.xls"
If strFilePath = Empty Then
MsgBox ("No TEST PLAN document was selected. Quitting...")
Exit Function
End If
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strFilePath & ";Extended Properties=Excel 8.0"
Set connection = CreateObject("ADODB.CONNECTION")
connection.Open ConnStr
Set ORs = CreateObject("ADODB.RECORDSET")
ORs.CursorType = 2
ORs.CursorLocation = 3
ORs.Open query, connection, adOpenStatic
Set sOpenExcel = ORs
Set ORs = Nothing
End Function
AND Calling in the following function
Sub sReadText()
Set rcdset = sOpenExcel("SELECT * FROM [Sheet1$]") ----> Calling
function to store the recordset
rcdset.MoveFirst -------> Fails here
Do Until rcdset.EOF
If (rcdset.Fields(0) <> Empty) Then
... action code..
End If
rcdset.MoveNext
Loop
rcdset.Close
End Sub
I'm using this in MsWord 200 as a macro.
Don't know where i'm going wrong.
Thanks
Nee
I'm trying to create a function to store the recordset with this
code...
Private Function sOpenExcel(query As String)
' strFilePath = "C:\myfile.xls"
If strFilePath = Empty Then
MsgBox ("No TEST PLAN document was selected. Quitting...")
Exit Function
End If
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strFilePath & ";Extended Properties=Excel 8.0"
Set connection = CreateObject("ADODB.CONNECTION")
connection.Open ConnStr
Set ORs = CreateObject("ADODB.RECORDSET")
ORs.CursorType = 2
ORs.CursorLocation = 3
ORs.Open query, connection, adOpenStatic
Set sOpenExcel = ORs
Set ORs = Nothing
End Function
AND Calling in the following function
Sub sReadText()
Set rcdset = sOpenExcel("SELECT * FROM [Sheet1$]") ----> Calling
function to store the recordset
rcdset.MoveFirst -------> Fails here
Do Until rcdset.EOF
If (rcdset.Fields(0) <> Empty) Then
... action code..
End If
rcdset.MoveNext
Loop
rcdset.Close
End Sub
I'm using this in MsWord 200 as a macro.
Don't know where i'm going wrong.
Thanks
Nee