Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    I pulled up the Tools-References. File Dialog was not there. I browsed, and could not find it. When I checked the database I downloaded, it wasn't there either. I checked everything that was checked on the downloaded database. It still didn't work.

  2. #17
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    File Dialog is part of the VBA library I mentioned in post 13. Follow the instructions in that post
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #18
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That means I did something wrong. This might take me a while. I'll keep you posted when I've figured it out. Thanks.

  4. #19
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    My VBA is very limited, but I'm trying. The author is doing a good job showing his work. I think I understand most of it. I'm having a problem with the last part of it. This is the FileDialog code from that database:

    Dim strSearchPath As String

    ' Set options for the dialog box.
    Dim F As FileDialog
    Set F = Application.FileDialog(msoFileDialogFilePicker)

    With F
    .Title = "Select any image in the required folder and click on 'Open'"
    .AllowMultiSelect = False

    ' Clear out the current filters & add our own
    .Filters.Clear
    .Filters.Add "Images", "*.bmp;*.gif;*.jpg;*.png;*.ico"

    ' Set the start folder
    ' By default, use existing folder ... or failing that use root folder C:\
    .InitialFileName = Nz(GetFolderPath(), "C:")

    ' Call the Open dialog routine.
    .Show

    ' Get the selected folder path
    strSourceFolder = .SelectedItems(1)
    strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, ""))
    End With

    The last part looks like he's getting the path and then taking only the actual name of the file (ie. Rock.jpg). Is this right?
    ' Get the selected folder path
    strSourceFolder = .SelectedItems(1)
    strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, ""))

  5. #20
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    The last part looks like he's getting the path and then taking only the actual name of the file (ie. Rock.jpg). Is this right?
    No - it is the left, so the path, but "" should be showing a backslash which for some reason does not show when posting unless you use the code tags

    Code:
    "\"
    using code tags also preserves formatting, so please use them in the future

  6. #21
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi
    When you post a block of code, please use the code tags (# button in the toolbar) to improve readability & fix layout issues caused by the forum software
    Also please post the entire code rather than just an extract

    I'm not sure whether you got this from the analystcave website or my example as all code of this type is basically the same
    Whatever its source, there are a couple of issues with the code.
    Particularly the part you commented on...which is incorrect

    Here is a fixed version which you can test
    I've added a debug line so you can see the result in the VBE Immediate window
    Recommend you always do that to test your code

    Code:
    Sub TestBrowse()
    
    Dim strSearchPath As String
    Dim strSourceFolder As String 'added this line
    
    ' Set options for the dialog box.
    Dim F As FileDialog
    Set F = Application.FileDialog(msoFileDialogFilePicker)
    
    With F
        .Title = "Select any image in the required folder and click on 'Open'"
        .AllowMultiSelect = False
        
        ' Clear out the current filters & add our own
        .Filters.Clear
        .Filters.Add "Images", "*.bmp;*.gif;*.jpg;*.png;*.ico"
        
        ' Set the start folder
        ' By default, use existing folder ... or failing that use root folder C:\
        '.InitialFileName = Nz(GetFolderPath(), "C:") 'needs external function
        .InitialFileName = Nz(CurrentProject.Path, "C:")  '<==alternative code
        
        ' Call the Open dialog routine.
        .Show
        
        ' Get the selected folder path
        strSourceFolder = .SelectedItems(1)
        'strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, "")) 'ERROR HERE - just returns the entire file path
        strSourceFolder = Left(strSourceFolder, InStrRev(strSourceFolder, "\") - 1) 'modified code to get folder path
        Debug.Print strSourceFolder 'added to test output from code
    End With
    End Sub
    Good luck with your project
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-27-2017, 01:09 PM
  2. Creating 'Common' VBA code
    By Nevsky78 in forum Programming
    Replies: 4
    Last Post: 06-18-2012, 02:07 AM
  3. common form fields
    By soulice in forum Forms
    Replies: 9
    Last Post: 04-05-2012, 02:58 PM
  4. Play sounds and Common Dialog Box example
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-29-2010, 06:49 AM
  5. Common Dialog control / ShowOpen method
    By phuile in forum Forms
    Replies: 0
    Last Post: 04-10-2009, 12:16 AM

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