Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Thanked 0 Times in 0 Posts

    Make file invisible through code (Access 2000)

    Actually my question is not for an Access forum, but does anybody know how can i make my file invisible through a code?
    I can do it only manually, by opening the Control panel.But i need to do it automatically when i makle a new Access file.
    The code i use is the following :

    Public Function CreateANewDB(tName As String)
    'Inputs: Directory and name of database. In the OnClick event of

    the Control ' on a form write : Call ANewDB("c:BEDepot.mdb")
    Dim wsp As Workspace, db As Database
    Dim db2 As Database
    Set db = CurrentDb
    Set wsp = DBEngine.Workspaces(0)
    Set db2 = wsp.CreateDatabase(tName, dbLangGeneral)
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Make file invisible through code (Access 2000)

    You can use Scripting to do this, but what's the use? Many users have set Windows Explorer to display hidden files.

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Arlington, Virginia, USA
    Thanked 3 Times in 3 Posts

    Re: Make file invisible through code (Access 2000)

    If you are referring to making file hidden in Windows Explorer, you can use FileSystemObject (FSO) methods to set or clear file attributes. Example:

    Public Sub SetFileAttribute(ByVal strFileSpec As String, _
    ByVal FileAttr As Scripting.FileAttribute, _
    ByVal intSetOrClear As Integer)
    On Error GoTo Err_Handler

    ' strFileSpec = full path of file
    ' File attribute to set or clear (see Scripting FileAttribute enum for all values)
    ' Hidden = 2
    ' ReadOnly = 1
    ' Normal = 0 (no attributes set)
    ' intSetOrClear 0 = clear, 1 = set

    Dim fso As New Scripting.FileSystemObject
    Dim fil As Scripting.File
    Dim strMsg As String

    Set fil = fso.GetFile(strFileSpec)

    Select Case intSetOrClear
    Case 0 ' Clear
    If fil.Attributes And FileAttr Then
    fil.Attributes = fil.Attributes - FileAttr
    strMsg = "Attribute cleared."
    strMsg = "Attribute not cleared - was not set."
    End If
    Case 1 ' Set
    If Not fil.Attributes And FileAttr Then
    fil.Attributes = fil.Attributes + FileAttr
    strMsg = "Attribute set."
    strMsg = "Attribute not set, was already set."
    End If
    End Select

    ' Test msg:
    MsgBox strMsg, vbInformation
    Debug.Print strMsg

    Set fso = Nothing
    Set fil = Nothing
    Exit Sub
    Select Case Err.Number
    Case 53 ' File not found
    strMsg = "Invalid file specification."
    MsgBox strMsg, vbExclamation, "FILE NOT FOUND"
    Case Else
    strMsg = "Error No " & Err.Number & ": " & Err.Description
    MsgBox strMsg, vbExclamation, "ERROR MESSAGE"
    End Select
    Resume Exit_Sub

    End Sub

    The MsgBox & Debug statements are for test purposes. Note that the file will still be visible in Windows Explorer if user selects option to display hidden files in Explorer. If you don't want "unauthorized" personnel to open your database you still need to use Access security, as previously discussed.


Posting Permissions

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