these code in Visual Basic 6.0 for connect with excel sheet but here give me error plz cheak it.line no. 10 give me error
plz any one reply me
1. Dim cn As ADODB.Connectio n
2. Dim rsT As ADODB.Recordset
3. Dim intTblCnt As Integer, intTblFlds As Integer
4. Dim strTbl As String
6. Dim rsC As ADODB.Recordset
7. Dim intColCnt As Integer, intColFlds As Integer
8. Dim strCol As String
9. Dim t As Integer, c As Integer, f As Integer
10. Set cn = New ADODB.Connectio n '(************* *****HERE give error that INVALID OUTSIDE PROSEDURE)
11. With cn
.Provider = "Microsoft.Jet. OLEDB.4.0"
.ConnectionStri ng = "Data Source=" & App.Path & _
"\ExcelSrc.xls; Extended Properties=Exce l 8.0;"
'.Provider = "MSDASQL"
'.ConnectionStr ing = "Driver={Micros oft Excel Driver (*.xls)};" & _
"DBQ=" & App.Path & "\ExcelSrc. xls; "
.CursorLocation = adUseClient
.Open
End With
Set rsT = cn.OpenSchema(a dSchemaTables)
intTblCnt = rsT.RecordCount
intTblFlds = rsT.Fields.Coun t
List1.AddItem "Tables: " & intTblCnt
List1.AddItem "--------------------"
For t = 1 To intTblCnt
strTbl = rsT.Fields("TAB LE_NAME").Value
List1.AddItem vbTab & "Table #" & t & ": " & strTbl
List1.AddItem vbTab & "--------------------"
For f = 0 To intTblFlds - 1
List1.AddItem vbTab & rsT.Fields(f).N ame & _
vbTab & rsT.Fields(f).V alue
Next
List1.AddItem "--------------------"
Set rsC = cn.OpenSchema(a dSchemaColumns, Array(Empty, Empty, strTbl, Empty))
intColCnt = rsC.RecordCount
intColFlds = rsC.Fields.Coun t
For c = 1 To intColCnt
strCol = rsC.Fields("COL UMN_NAME").Valu e
List1.AddItem vbTab & vbTab & "Column #" & c & ": " & strCol
List1.AddItem vbTab & vbTab & "--------------------"
For f = 0 To intColFlds - 1
List1.AddItem vbTab & vbTab & rsC.Fields(f).N ame & _
vbTab & rsC.Fields(f).V alue
Next
List1.AddItem vbTab & vbTab & "--------------------"
rsC.MoveNext
Next
rsC.Close
List1.AddItem "--------------------"
rsT.MoveNext
Next
rsT.Close
cn.Close
plz any one reply me
1. Dim cn As ADODB.Connectio n
2. Dim rsT As ADODB.Recordset
3. Dim intTblCnt As Integer, intTblFlds As Integer
4. Dim strTbl As String
6. Dim rsC As ADODB.Recordset
7. Dim intColCnt As Integer, intColFlds As Integer
8. Dim strCol As String
9. Dim t As Integer, c As Integer, f As Integer
10. Set cn = New ADODB.Connectio n '(************* *****HERE give error that INVALID OUTSIDE PROSEDURE)
11. With cn
.Provider = "Microsoft.Jet. OLEDB.4.0"
.ConnectionStri ng = "Data Source=" & App.Path & _
"\ExcelSrc.xls; Extended Properties=Exce l 8.0;"
'.Provider = "MSDASQL"
'.ConnectionStr ing = "Driver={Micros oft Excel Driver (*.xls)};" & _
"DBQ=" & App.Path & "\ExcelSrc. xls; "
.CursorLocation = adUseClient
.Open
End With
Set rsT = cn.OpenSchema(a dSchemaTables)
intTblCnt = rsT.RecordCount
intTblFlds = rsT.Fields.Coun t
List1.AddItem "Tables: " & intTblCnt
List1.AddItem "--------------------"
For t = 1 To intTblCnt
strTbl = rsT.Fields("TAB LE_NAME").Value
List1.AddItem vbTab & "Table #" & t & ": " & strTbl
List1.AddItem vbTab & "--------------------"
For f = 0 To intTblFlds - 1
List1.AddItem vbTab & rsT.Fields(f).N ame & _
vbTab & rsT.Fields(f).V alue
Next
List1.AddItem "--------------------"
Set rsC = cn.OpenSchema(a dSchemaColumns, Array(Empty, Empty, strTbl, Empty))
intColCnt = rsC.RecordCount
intColFlds = rsC.Fields.Coun t
For c = 1 To intColCnt
strCol = rsC.Fields("COL UMN_NAME").Valu e
List1.AddItem vbTab & vbTab & "Column #" & c & ": " & strCol
List1.AddItem vbTab & vbTab & "--------------------"
For f = 0 To intColFlds - 1
List1.AddItem vbTab & vbTab & rsC.Fields(f).N ame & _
vbTab & rsC.Fields(f).V alue
Next
List1.AddItem vbTab & vbTab & "--------------------"
rsC.MoveNext
Next
rsC.Close
List1.AddItem "--------------------"
rsT.MoveNext
Next
rsT.Close
cn.Close