Consulting

Results 1 to 4 of 4

Thread: Solved: How to access database file properties?

  1. #1
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location

    Question Solved: How to access database file properties?

    Hi, all,

    Is there a way (I don't know, using API or something?) to determine whether the current database file is marked as read-only? I'm having issues with a customer trying to run a tool off CD (which of course means it's read-only).

    When any one specific operation fails, I can react with a specific error-handling message. But for concision's sake, I would like to just put something in the Form_Load event of my main switchboard to say, "If this database file is read-only, give the user this reminder message that the file will not run all its functions properly, and that the user should save the file to an updatable location and change its read-only property."

    So... what would be the syntax to make my code ask Windows whether the file's Read-Only property is set? Thanks in advance for any thoughts!!

    ~ eed
    With program specs this fickle, you've just got to believe in Discord.

  2. #2
    VBAX Regular GP George's Avatar
    Joined
    Jul 2004
    Location
    Puget Sound, WA
    Posts
    26
    Location
    The API calls to identify connected drives and their attributes is here: http://www.mvps.org/access/api/api0003.htm

    You can combine the fDriveType function form the above code with a call to the CurDir function to identify where the database is currently running, and, if it is the CD ROM, display your message.

    HTH

    George
    "We're all in this together."
    -Red Green

  3. #3
    VBAX Regular zilpher's Avatar
    Joined
    Nov 2004
    Location
    Swindon, UK
    Posts
    30
    Location
    This will tell you if a drive is a CD ROM:

    [VBA]Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

    Sub foo()

    'valid returns are:
    '2 Removeable disk (such as floppy drive)
    '3 Fixed drive
    '4 Remote or Network drive
    '5 CD Rom
    '6 RAM Disk
    ' all other returns (usually 1) drive type unknown

    If GetDriveType(Left(CurrentDb.Name, 3)) = 5 Then MsgBox "CDROM!"
    End Sub
    [/VBA]

    How about the Updateable property of the currentdb object?

    [VBA]Debug.Print CurrentDb.Updatable[/VBA]

    HTH

  4. #4
    VBAX Contributor
    Joined
    Jun 2004
    Location
    Texas
    Posts
    139
    Location
    Yes, the CurrentDb.Updatable property captured what I needed to know. That was simple, wonder why I didn't think of it. The DriveType approach would probably allow me to accomplish the same thing, but the Updatable property is more straightforward (and it will flag a read-only file regardless of drive).

    Thanks so much for the help, zilpher and GP George!!!
    With program specs this fickle, you've just got to believe in Discord.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •