Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Nov 2003
    Posts
    55

    Unanswered: File-Sytem for Access?

    Are there any file system objects that I can use in Access? I want to allow users to be able to select files and directories to provide input for a function. Is there anything available to aid in my needs?


    Thanks,

    Animaul

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Use a file dialog box.

  3. #3
    Join Date
    Nov 2003
    Posts
    55
    From what I have read there is no file dialog box for Access. If there is what is it called?

    Thanks


    Originally posted by CyberLynx
    Use a file dialog box.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    The job is easily done using API calls. To start with, create a code module which you can later name Dialogs. Place the following into it:

    [Start of code]

    'FOR THE 'OPEN' AND 'SAVE' DIALOG BOXES.
    Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Boolean
    Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Boolean

    Type MSA_OPENFILENAME
    ' Filter string used for the File Open dialog filters.
    ' Use MSA_CreateFilterString() to create this.
    ' Default = All Files, *.*
    strFilter As String
    ' Initial Filter to display.
    ' Default = 1.
    lngFilterIndex As Long
    ' Initial directory for the dialog to open in.
    ' Default = Current working directory.
    strInitialDir As String
    ' Initial file name to populate the dialog with.
    ' Default = "".
    strInitialFile As String
    strDialogTitle As String
    ' Default extension to append to file if user didn't specify one.
    ' Default = System Values (Open File, Save File).
    strDefaultExtension As String
    ' Flags (see constant list) to be used.
    ' Default = no flags.
    lngFlags As Long
    ' Full path of file picked. On OpenFile, if the user picks a
    ' nonexistent file, only the text in the "File Name" box is returned.
    strFullPathReturned As String
    ' File name of file picked.
    strFileNameReturned As String
    ' Offset in full path (strFullPathReturned) where the file name
    ' (strFileNameReturned) begins.
    intFileOffset As Integer
    ' Offset in full path (strFullPathReturned) where the file extension begins.
    intFileExtension As Integer
    End Type

    Const ALLFILES = "All Files"

    Type OPENFILENAME
    lStructSize As Long
    hWndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As Long
    nMaxCustrFilter As Long
    NFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustrData As Long
    lpfnHook As Long
    lpTemplateName As Long
    End Type

    Const OFN_ALLOWMULTISELECT = &H200
    Const OFN_CREATEPROMPT = &H2000
    Const OFN_EXPLORER = &H80000
    Const OFN_FILEMUSTEXIST = &H1000
    Const OFN_HIDEREADONLY = &H4
    Const OFN_NOCHANGEDIR = &H8
    Const OFN_NODEREFERENCELINKS = &H100000
    Const OFN_NONETWORKBUTTON = &H20000
    Const OFN_NOREADONLYRETURN = &H8000
    Const OFN_NOVALIDATE = &H100
    Const OFN_OVERWRITEPROMPT = &H2
    Const OFN_PATHMUSTEXIST = &H800
    Const OFN_READONLY = &H1
    Const OFN_SHOWHELP = &H10
    '================================================= =========


    Function IsLoaded(ByVal strFormName As String) As Integer
    ' Returns True if the specified form is open in Form view or Datasheet view.

    Const conObjStateClosed = 0
    Const conDesignView = 0

    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
    If Forms(strFormName).CurrentView <> conDesignView Then
    IsLoaded = True
    End If
    End If

    End Function


    'procedure MSAOF_to_OF
    Private Sub MSAOF_to_OF(msaof As MSA_OPENFILENAME, of As OPENFILENAME)
    '-----------------------------------------------------------------
    ' This sub converts from the friendly MSAccess structure to the
    ' win32 structure.
    '-----------------------------------------------------------------
    Dim strFile As String * 512

    ' Initialize some parts of the structure.
    of.hWndOwner = Application.hWndAccessApp
    of.hInstance = 0
    of.lpstrCustomFilter = 0
    of.nMaxCustrFilter = 0
    of.lpfnHook = 0
    of.lpTemplateName = 0
    of.lCustrData = 0

    If msaof.strFilter = "" Then
    of.lpstrFilter = MSA_CreateFilterString(ALLFILES)
    Else
    of.lpstrFilter = msaof.strFilter
    End If
    of.NFilterIndex = msaof.lngFilterIndex

    of.lpstrFile = msaof.strInitialFile _
    & String$(512 - Len(msaof.strInitialFile), 0)
    of.nMaxFile = 511

    of.lpstrFileTitle = String$(512, 0)
    of.nMaxFileTitle = 511

    of.lpstrTitle = msaof.strDialogTitle

    of.lpstrInitialDir = msaof.strInitialDir

    of.lpstrDefExt = msaof.strDefaultExtension

    of.Flags = msaof.lngFlags

    of.lStructSize = Len(of)

    End Sub

    'procedure OF_to_MSAOF
    Private Sub OF_to_MSAOF(of As OPENFILENAME, msaof As MSA_OPENFILENAME)
    '---------------------------------------------------------------------
    ' This sub converts from the win32 structure to the friendly MSAccess
    ' structure.
    '---------------------------------------------------------------------
    msaof.strFullPathReturned = Left$(of.lpstrFile, _
    InStr(of.lpstrFile, Chr$(0)))
    msaof.strFileNameReturned = of.lpstrFileTitle
    msaof.intFileOffset = of.nFileOffset
    msaof.intFileExtension = of.nFileExtension

    End Sub

    'procedure MSA_GetSaveFileName
    Public Function MSA_GetSaveFileName(msaof As MSA_OPENFILENAME) As Integer
    '------------------------------------------------------
    ' Opens the file save dialog.
    '------------------------------------------------------
    Dim of As OPENFILENAME
    Dim intRet As Integer

    MSAOF_to_OF msaof, of
    of.Flags = of.Flags Or OFN_HIDEREADONLY
    intRet = GetSaveFileName(of)
    If intRet Then
    OF_to_MSAOF of, msaof
    End If
    MSA_GetSaveFileName = intRet

    End Function

    'procedure MSA_CreateFilterString
    Function MSA_CreateFilterString(ParamArray varFilt() As Variant) As String
    '-------------------------------------------------------------------
    ' Creates a filter string from the passed in arguments.
    ' Returns "" if no args are passed in.
    ' Expects an even number of args (filter name, extension), but
    ' if an odd number is passed in, it appends *.*
    '-------------------------------------------------------------------
    Dim strFilter As String
    Dim intRet As Integer
    Dim intNum As Integer

    intNum = UBound(varFilt)
    If (intNum <> -1) Then
    For intRet = 0 To intNum
    strFilter = strFilter & varFilt(intRet) & Chr$(0)
    Next
    If intNum Mod 2 = 0 Then
    strFilter = strFilter & "*.*" & Chr$(0)
    End If

    strFilter = strFilter & Chr$(0)
    Else
    strFilter = ""
    End If

    MSA_CreateFilterString = strFilter

    End Function

    [end of code]
    =============================================

    NOW...Create a Command button on your form and place the following code into its' Click event:

    [start of code]

    Dim msaof As MSA_OPENFILENAME
    Dim strStartPath As String, Strg as String

    ' Set options for the dialog box.
    msaof.strDialogTitle = "Please Select File...."
    If strStartPath = "" Then msaof.strInitialDir = "C:\" Else msaof.strInitialDir = strStartPath
    msaof.strFilter = MSA_CreateFilterString("All Files (*.*)", "*.*")
    msaof.strInitialFile = "_"

    ' Call the Open File dialog routine.
    MSA_GetSaveFileName msaof

    ' Return the path and file name.
    If Trim(msaof.strFullPathReturned) <> "" Then Strg = Trim(msaof.strFullPathReturned)
    Strg = Trim(Strg)
    If Right$(Strg, 1) <> "\" Then
    Dim i As Integer, c As String
    For i = Len(Strg) To 1 Step -1
    c = Mid(Strg, i, 1)
    If c = "\" Then Exit For
    Next i
    a = Left$(Strg, (Len(Strg) - (Len(Strg) - i)))
    End If
    WhateverVariableOrControl = Strg

    [end of code]

    ======================================

    When the button is clicked, a dialog box is displayed. hope this helps.

  5. #5
    Join Date
    Nov 2003
    Posts
    55
    I will give it a shot. I can't thank you enough. I appriciate the effort. You did not Have to go throu all of that.

    Thanks,

    Animual

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Well Animaul, that's what we are here for....to help each other the best we can.

    You will also notice that I have also included a function named "IsLoaded". Like most, I'm sure you are already familiar with it. But just in case you are not...it simply lets you know if a specific FORM in your database is loaded. For example:

    If IsLoaded("myForm") then
    MsgBox "My Form named myForm is Loaded"
    End If

    Anywayyyys..... glad to help.

  7. #7
    Join Date
    Nov 2003
    Posts
    55
    What are the hexidecimal values that the Flag constants are set to? And where can I find a list of those values?

    Thanks,

    Animaul

  8. #8
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Originally posted by Animaul
    What are the hexidecimal values that the Flag constants are set to? And where can I find a list of those values?

    Thanks,

    Animaul
    You can use the appi Viewer or download the api Guide from www.allapi.net for free

  9. #9
    Join Date
    Nov 2003
    Posts
    1,487
    There ya go....

  10. #10
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Originally posted by CyberLynx
    There ya go....
    Bz the way is there any FileSystem in Accesse 97? If yes what should I include as a Reference?

  11. #11
    Join Date
    Nov 2003
    Posts
    1,487
    Check your References list for:

    Microsoft Common Dialog Control x.x

    if you have it...use it.

    If you have Visual Basic installed onto your system you can use this reference. I personally prefer to use the API's. No worries that way for carrying the control with your package and ensuring the control is functional for end users (this can be a real headache at times).

  12. #12
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Originally posted by CyberLynx
    Check your References list for:

    Microsoft Common Dialog Control x.x

    if you have it...use it.

    If you have Visual Basic installed onto your system you can use this reference. I personally prefer to use the API's. No worries that way for carrying the control with your package and ensuring the control is functional for end users (this can be a real headache at times).
    Thank you for your reply, but what I ment was something else, I mean What should I need to write sometheing like that

    Sub CreateFolder
    &nbsp;&nbsp; Dim fso, fldr
    &nbsp;&nbsp; Set fso = CreateObject("Scripting.FileSystemObject")
    &nbsp;&nbsp; Set fldr = fso.CreateFolder("C:\MyTest")
    End Sub

    What are the prefernces I need under Access97? Thanks

  13. #13
    Join Date
    Nov 2003
    Posts
    1,487
    What exactly are you wanting to do....Create a folder on drive?

  14. #14
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Originally posted by CyberLynx
    What exactly are you wanting to do....Create a folder on drive?
    Creating folders, files, search for files , I want to use the Scripting.FileSystemObject
    in Access 97
    Thanks

  15. #15
    Join Date
    Nov 2003
    Posts
    1,487
    Ohhhh, I see. Sorry, I can't help you with that. I never use it since it's so easy to do through VBA code.

    Sorry bout that.

Posting Permissions

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