API Call To Change a File to Read Only

colette

Registered User.
Local time
Today, 12:04
Joined
Sep 23, 2005
Messages
22
From inside one database, I create a blank database from which I copy all of the objects to the new database. I use createdatabase to make the blank database. Then I loop through the linked tables and make local copies in the new db. I then copy the rest of the objects.

I would like to set the file to Read-Only when I am done creating it. Does anyone know how to do that programmatically.

Thank you.
 
This should go close: -

Code:
Option Explicit
Option Compare Text


Sub Test()

    If Not SetFileAttributes("C:\Test\AndOr.mdb", vbReadOnly, vbHidden) Then
        MsgBox "Error while setting file attributes."
    End If

End Sub


Public Function SetFileAttributes(ByVal strPathAndName As String, _
                             ParamArray vntArgList() As Variant) As Boolean
    
    Dim intIndex      As Integer
    Dim intAttributes As Integer
    
    On Error GoTo ErrorHandler
    
    For intIndex = LBound(vntArgList) To UBound(vntArgList)
        intAttributes = intAttributes + vntArgList(intIndex)
    Next intIndex
    
    SetAttr strPathAndName, intAttributes

    SetFileAttributes = True
    
ExitProcedure:
    Exit Function

ErrorHandler:
    [color=green]'This Function defaults to a False return value.[/color]
    Resume ExitProcedure

End Function
Hope that helps.

Regards,
Chris.
 
SetAttr filename, attribute

Thank you! I knew there had to be a relatively simple way.

SetAttr c:\test.mdb, vbReadOnly
 
Searching the forum is a great way to discover and learn the answers to your Access programming questions. If you had tried ;) then you would have found quite a few postings like this one...

Change file read only property
 
Be careful what you assume

I would be careful writing emails like that. It is a bit offensive. I spent a long time searching the web and searching the site to no avail. My searches did not bring up any helpful results. While searching, I also helped others by responding to their inquires. Why do you think I went to a the forum to begin with... to see if someone had posted a hint that would help me. When I didn't find one, I asked.

Next time be more careful in your accusations.
 
In the same context, wouldnt like my access file to be moved or even to the worst, copied from its installation folder. How can i achieve this.:rolleyes:
 
Network Security

Hi,
I am not sure if there is a way from Access, but the safest way is to make sure that the directory on the network that it is placed in is locked down. Make sure only the appropriate users have full rights (read,write, execute...etc). For the rest, just give them read.
Colettte
 
I come across a problem the other way around ( I would!)

I distribute a package which has front and back end. On quite a few machines, especially with XP operating system, the back end datafile is read only on installation and refuses to change with the file system commands in the setup module.

What really bugs me (Pardon the pun) is that the front end logic file changes quite happily to read/write. In the demonstration I send out, both files reside in the same directory.
 
The problem with me is that my applications are used both at the main office and also remote locations. But we have very stubbon Data Clerks who keep on shipping my applications to different locations and even to the worst, out of the office.:o
This puts me back because at deployment,a shortcut to the file in the installation folder is put on the desktop, so if they remove the file then i have to send them another.
Any Ideas!!
 
Last edited:
Force the db to be shut down if the db is not located in the right [expected] directory when it is opened.
 
Correct. Big boy....i will give that a go.
 
Make sure only the appropriate users have full rights (read,write, execute...etc). For the rest, just give them read.
Bear in mind though that anyone opening the db with a read only permission will open it exclusivly, locking everbody else out.

Peter
 

Users who are viewing this thread

Back
Top Bottom