Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Mar 2006
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Path with the last day (Access 2000)

    I am opening sucesfully a database with the following function
    Public Const CnstSurvey = "C:BEsurvey.mdb"
    Public Function OpenSurvey()
    Dim appAccess As Access.Application
    Set appAccess = CreateObject("Access.Application")
    appAccess.OpenCurrentDatabase CnstSurvey
    End Function
    I want however to have databases ending with different days, for example
    Survey20060327
    or
    Survey20060326
    and to open that database which has the latest date. Is it possible ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Path with the last day (Access 2000)

    Try this:
    <code>
    ' Path including backslash
    Public Const strPath = "C:BE"

    Public Sub OpenSurvey()
    Dim appAccess As Access.Application
    Dim strFile As String
    Dim strLatest As String

    strFile = Dir(strPath & "Survey*.mdb")
    ' Loop through the files in the folder
    Do While Not strFile = ""
    ' See if we have a later file
    If strFile > strLatest Then
    strLatest = strFile
    End If
    ' And on to the next
    strFile = Dir
    Loop

    ' Did we find a file?
    If Not strLatest = "" Then
    ' If so, open it
    Set appAccess = CreateObject("Access.Application")
    appAccess.OpenCurrentDatabase(strPath & strLatest)
    End If
    End Sub</code>

Posting Permissions

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