VB6 Reading data from Mdb to MS Office web component (excel)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wernerh
    New Member
    • Jul 2007
    • 104

    VB6 Reading data from Mdb to MS Office web component (excel)

    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.Connectio n
    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.Connecti onString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " + App.Path & "\data\adodb1s. mdb"

    strDBName = App.Path & "\" & "\data\adodb1s. mdb"

    cn.ConnectionSt ring = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & strDBName & ";Persist Security Info=false"
    cn.Open (strDBName)
    Set oSchema = cn.OpenSchema(a dSchemaTables)

    Do Until oSchema.EOF

    rs.Open "select * from [" & oSchema!table_n ame & "]", cn
    intFldCnt = rs.Fields.Count - 1

    For i = 1 To intFldCnt
    Report1.Spreads heet1.Cells(100 , i) = rs.Fields(i).Na me
    If TextWidth(rs.Fi elds(i).Name) > sngColWid Then
    sngColWid = TextWidth(rs.Fi elds(i).Name)
    End If
    Next i

    j = 2
    Do Until rs.EOF
    For i = 1 To intFldCnt
    Report1.Spreads heet1.Cells(j, i) = rs.Fields(i).Va lue
    Next i
    j = j + 1
    rs.MoveNext
    Loop
    rs.Close
    Debug.Print oSchema!table_n ame

    oSchema.MoveNex t
    Loop
    Wait.Hide

    Screen.MousePoi nter = vbNormal
    Exit Sub
    End Sub
  • smartchap
    New Member
    • Dec 2007
    • 236

    #2
    May be u correct the following line:

    strDBName = App.Path & "\" & "\data\adodb1s. mdb"

    with

    strDBName = App.Path & "\data\adodb1s. mdb"

    meanwhile I will try to check ur code.

    Comment

    Working...