Solved

VB6 - DAO - ReadOnly don't work

Posted on 1999-01-28
7
805 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
7 Comments
 
LVL 13

Expert Comment

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

0
 
LVL 3

Author Comment

by:greisch
Comment Utility
I doesn't work.
0
 
LVL 12

Expert Comment

by:jgv
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Author Comment

by:greisch
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now