Solved

VB6 - DAO - ReadOnly don't work

Posted on 1999-01-28
7
815 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 69
Sub or Function is not defined 6 43
VB6 - Cannot type when doing an extract from MSHFlexgrid to Excel 6 20
transition to visual .net from vb6 5 41
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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