PDA

Click to See Complete Forum and Search --> : Accessing Data from an Access Database on CD-ROM


Elias
Jul 11th, 2000, 08:00 AM
Can anyone tell me if its possible to write code to access data from an access database that is burned onto a CD-ROM? I keep getting the following error when I try. Do I need to change my cursor location or locktype in my ado code?

Error:
The Microsoft Jet database engine cannot open the file 'E:\alprgama.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

Code:
Private Sub Form_Load()
Dim rst As adodb.Recordset
Set rst = CreateObject("adodb.recordset")
rst.LockType = adLockReadOnly
rst.CursorLocation = adUseServer
rst.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=E:\alprgama.mdb"
rst.Open "select * from equipment"
While Not rst.EOF
List1.AddItem rst!equipid
rst.MoveNext
Wend
End Sub

-Elias

Clunietp
Jul 11th, 2000, 11:32 AM
example of reading a read-only MDB file:


Dim cn As New Connection
Dim rs As New Recordset



cn.Mode = adModeRead
cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=Nwind.mdb"


rs.Open "Select * from Customers", cn

MsgBox rs(1)


you might have to explicitly create a connection object for your RS

Elias
Jul 11th, 2000, 01:22 PM
Actually, that didn't work, but the following did! Thanks for the help.

Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim errX As ADODB.Error
'On Error Resume Next
On Error GoTo FormError
cn.Mode = adModeShareDenyWrite ' ******* This mode is what you need to make it work for a db burned on cd *******

cn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=E:\alprgama.mdb"

rs.Open "Select * from equipment", cn
'If Len(rs!equipid) = 0 Then
While Not rs.EOF
List1.AddItem rs!equipid
rs.MoveNext
Wend
'End If
Exit Sub
FormError:
For Each errX In cn.Errors
MsgBox errX.Description
Next errX