Hi all, I have a mdb with data in it. In my VB project I have Excel embedded on a form. The following code I am using to get data from the db and then "paste"it into the excel sheet. I get a read access error. The same database is feeding a Datagrid and exporting to excel (outside vb) with no hassle. Can someone tell me if they can spot a problem. Is there maybe a better way to do this other than this code. Thanks
Error Message is : Records cannot be read, no permission on 'MSysACEs'
VB Code:
Private Sub Command14_Click()
Dim cn As New ADODB.Connection
Dim oSchema As ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim intFldCnt As Integer
Dim i As Integer
Dim j As Integer
Dim sngColWid As Single
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + App.Path & "\data\adodb1s.mdb"
strDBName = App.Path & "\" & "\data\adodb1s.mdb"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName & ";Persist Security Info=false"
cn.Open (strDBName)
Set oSchema = cn.OpenSchema(adSchemaTables)
Do Until oSchema.EOF
rs.Open "select * from [" & oSchema!table_name & "]", cn
intFldCnt = rs.Fields.Count - 1
For i = 1 To intFldCnt
Report1.Spreadsheet1.Cells(100, i) = rs.Fields(i).Name
If TextWidth(rs.Fields(i).Name) > sngColWid Then
sngColWid = TextWidth(rs.Fields(i).Name)
End If
Next i
j = 2
Do Until rs.EOF
For i = 1 To intFldCnt
Report1.Spreadsheet1.Cells(j, i) = rs.Fields(i).Value
Next i
j = j + 1
rs.MoveNext
Loop
rs.Close
Debug.Print oSchema!table_name
oSchema.MoveNext
Loop
Wait.Hide
Screen.MousePointer = vbNormal
Exit Sub
End Sub