?
Solved

VB6 - DAO - ReadOnly don't work

Posted on 1999-01-28
7
Medium Priority
?
827 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

649 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