Solved

VB6 - DAO - ReadOnly don't work

Posted on 1999-01-28
7
817 Views
Last Modified: 2013-12-25
I want to open a database in ReadOnly mode.

set db = opendatabase("c:\temp\test.mdb", ReadOnly := True)

I can always write to the tables of this db, even open in ReadOnly.

Is it a bug ?

I want to have an error when I try to write to this database. Is it possible ? How ?

Thanks.
0
Comment
Question by:greisch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1499558
Try without using a named argument.
Set <database> = OpenDatabase(dbname, options, readonly, connect)

0
 
LVL 3

Author Comment

by:greisch
ID: 1499559
I doesn't work.
0
 
LVL 12

Expert Comment

by:jgv
ID: 1499560
If you're creating a record set, specify that as read only. The following code produces an error when attempting to add a record.

Dim db As Database
Dim rs As Recordset

Set db = OpenDatabase("c:\temp\test.mdb")
Set rs = db.OpenRecordset("Table1", dbOpenDynaset, dbReadOnly)

With rs
    .AddNew
    !Field1 = "newinfo"
    .Update
End With
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:greisch
ID: 1499561
To jgv:

It'working... But I want to have the DATABASE readonly. So I don't need to specify dbReadOnly each time I open a recordset.
I thought use that to open the database read-only for users and read-write for managers. So I don't have to change my code.

Thanks
0
 
LVL 1

Expert Comment

by:chdy
ID: 1499562
Option Explicit

Dim ws As Workspace
Dim db As Database
Dim rs As Recordset

Dim sql as String

Private Sub Command2_Click()
Dim iCNT%
 
    Set ws = Workspaces(0)
   
    Set db = ws.OpenDatabase("C:\Door\Door.mdb")
   
    sql = "select * from Door"
   
    Set rs = db.OpenRecordset(sql)
:
:
:
      sTerm = DateDiff("s", sSTime, sETime)
   
      rs.AddNew '<- Insert Data
   
      rs.Fields("DoorOPT") = sSND & " " & sSNT
      rs.Fields("DoorCLT") = sEND & " " & sENT
      rs.Fields("DoorTRM") = sTerm

      rs.Update '<- Very Important

Do you know above content?
Good Luck...
0
 
LVL 3

Author Comment

by:greisch
ID: 1499563
Excuse me but I don't see the relation between my question and your answer !!!
0
 
LVL 1

Accepted Solution

by:
jonder earned 100 total points
ID: 1499564
I want to open a database in ReadOnly mode.

set db = opendatabase("c:\temp\test.mdb", ReadOnly := True)

Is it a bug ?

I want to have an error when I try to write to this database. Is it possible ? How ?

Set db = DBEngine.Workspaces(0).OpenDatabase("c:\temp\test.mdb", False, False)
         ^
         This is the Read Only set it to False as above...

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question