?
Solved

VB6 - DAO - ReadOnly don't work

Posted on 1999-01-28
7
Medium Priority
?
825 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
Industry Leaders: 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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