Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 3rd, 2008, 06:47 AM
Member
 
Join Date: Jul 2007
Posts: 88
Default 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.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
Reply
  #2  
Old September 5th, 2008, 10:50 AM
Member
 
Join Date: Dec 2007
Posts: 91
Default

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.
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles