Results 1 to 12 of 12
  1. #1
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74

    Browse and Open Folder Based on Matching Form Field

    Greetings,



    I'm wondering if a simple code exists that can be applied to a command button on a Form to perform the following functions:
    - browse specific folder on share drive
    - open specific subfolder that matches information on the open Form

    Any guidance would be much appreciated!

    Thanks,

    Tommy

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Tom,

    try something like:

    Code:
          With Application.FileDialog(msoFileDialogFilePicker)
                 .InitialFileName = "c:\yourMainDirectory\" & me.FORMFIELDsubDirectory
                 .Show
          End With

  3. #3
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    Hi Adam,

    I inserted the code in the command button "on click" procedure, but got error message
    "The expression On Click you entered as the event property setting produced the following error: Invalid outside procedure."

    Any ideas? The directory I used is C:\Users\Tommy\Documents\Access
    The Form field is "Last Name"

    Thanks in advance for your help.

    Tommy

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    YES, my guess would be that since the message says "invalid outside procedure", you forgot to put the code I posted INSIDE your actual procedure declaration lines. for instance:

    Code:
    private sub button_click()
    
    
    end sub
    that possible??

    I know you said otherwise though. Care to post your entire procedure?? my other guess would be that if you did this:
    Code:
    .initialfilename = "directory" & me.lastname
    you should be fine. spaces in field names on forms are automatically translated to (_) underscores in code references (I think). So your code might look like "last_name"

  5. #5
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    Here is the code inserted:

    Private Sub Command88_Click()
    With APPLICATION.FileDialog(msoFileDialogFilePicker)
    .InitialFileName = "c:\Users\Tommy\Documents\Access" & Me.[Last Name:]subDirectory
    .Show
    End With
    End Sub

    Last Name: is the Form field whose contents (Smith) would match a "Smith" folder in c:\Users\Tommy\Documents\Access

    Tommy

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    geez...

    change:
    Quote Originally Posted by Tomfernandez1 View Post
    )
    .InitialFileName = "c:\Users\Tommy\Documents\Access" & Me.[Last Name:]subDirectory
    to:

    Code:
    .InitialFileName = "c:\Users\Tommy\Documents\Access" & Me.[Last Name]

  7. #7
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    Adam- still coming up with same error message after using the latest code revision. Might you have a database with the code that you could share? I find this method to work best so I can compare my database/codes to one that actually works.

    Tommy

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    I can do that, or upload yours and I'll fix it. let me know. I'd prefer yours over mine.

    my db's are always over complex for my own enjoyment. Hence, I always have to modify code to make it relevant to someone else. And readable too!

  9. #9
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    Here is a copy of the database I use that has button "command496" on the driver Form. This button has the code and when clicked, an error occurs with an option to 'debug'...

    Thanks for the assistance, Adam!

  10. #10
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    and i said before, the intellisense changes control names with spaces in it to control names with (_) in them when you reference them in VBA. reference it correctly and it should work.

    you still have it written as:

    Code:
    "directory\" & me.[LAST NAME]
    when you use intellisense to help you, it becomes:
    Code:
    "directory\" & me.last_name
    these vba tags aren't the greatest here, so the above code should read "last_name". for some reason, underscores aren't being parsed. I have no idea why.

    please refer to my earlier posts.

  11. #11
    Tomfernandez1 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Posts
    74
    Adam- here is the code I found works:

    Private Sub Command496_Click()

    Dim fd As FileDialog

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    fd.InitialFileName = "C:\Documents and Settings\tommyf\My Documents\Access\" & Me.LAST_NAME

    fd.Show
    End Sub

    Thanks, again, for your assistance!

    Have a great day!

    Tommy

  12. #12
    naseerrahaman is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    India
    Posts
    12

    is their any way to open text files with word document with these codings

    Hi Team,

    could any of you help me to open text files with word document with the below codes.

    I am failing to write correct variables which help me browse and open text files with word document.

    Thanks in advance for the help.

    Option Explicit
    Function BrowseForFolder(Optional OpenAt As Variant) As Variant
    'Function purpose: To Browser for a user selected folder.
    'If the "OpenAt" path is provided, open the browser at that directory
    'NOTE: If invalid, it will open at the Desktop level
    Dim ShellApp As Object

    'Create a file browser window at the default folder
    Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

    'Set the folder to that selected. (On error in case cancelled)
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0

    'Destroy the Shell Application
    Set ShellApp = Nothing

    'Check for invalid or non-entries and send to the Invalid error
    'handler if found
    'Valid selections can begin L: (where L is a letter) or
    Select Case Mid(BrowseForFolder, 2, 1)
    Case Is = ":"
    If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
    Case Is = "\"
    If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
    Case Else
    GoTo Invalid
    End Select

    Exit Function
    Invalid:
    'If it was determined that the selection was invalid, set to False
    BrowseForFolder = False
    End Function

    Sub test1()
    Dim result As String
    result = BrowseForFolder
    Select Case result
    Case Is = False
    result = "an invalid folder!"
    Case Else
    'don't change anything
    End Select
    MsgBox "You selected " & result, _
    vbOKOnly + vbInformation
    End Sub
    Sub test2()
    Dim OpenBrowseAt As String
    MsgBox "Please choose a folder to use as your starting point!"
    OpenBrowseAt = BrowseForFolder

    Select Case OpenBrowseAt
    Case Is = False
    MsgBox "You selected an invalid folder!" & vbNewLine & _
    "I will now open a new browser as" & vbNewLine & _
    "if you made no selection!", vbOKOnly + vbInformation
    Case Else
    MsgBox "I will now open a new browser at" & vbNewLine & _
    "your chosen location:" & vbNewLine & _
    OpenBrowseAt, vbOKOnly + vbInformation
    End Select
    BrowseForFolder (OpenBrowseAt)

    End Sub

    Regards,
    Rahaman.
    Attached Files Attached Files

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Browse For Folder Example
    By pkstormy in forum Code Repository
    Replies: 6
    Last Post: 01-08-2012, 04:13 PM
  2. Button to Open a Specific Folder
    By dnelms in forum Programming
    Replies: 1
    Last Post: 04-08-2011, 10:05 AM
  3. Browse to external file while in a form
    By michaeljohnh in forum Import/Export Data
    Replies: 9
    Last Post: 09-22-2010, 09:33 AM
  4. Enter a folder name and open that folder
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 09-05-2010, 04:39 PM
  5. Partial Matching based Queries
    By Yatesb in forum Queries
    Replies: 0
    Last Post: 02-23-2009, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums