Solved

Command button not taking user to proper path

Posted on 2014-02-25
5
303 Views
Last Modified: 2014-02-26
On a form I have a command button that when clicked is supposed to take the user to...

B:\Dropbox\Business Documents\Database\Database Images

It isn't doing this.  Here is the code.  Can someone tell me what I'm doing wrong?

Private Sub cmdAdd_Click()
' User asked to add a new photo
Dim strPath As String

    ' Grab a copy of the Office file dialog
    With Application.FileDialog(msoFileDialogFilePicker)
        ' Select only one file
        .AllowMultiSelect = False
        ' Set the dialog title
        .Title = "Locate the image file"
        ' Set the button caption
        .ButtonName = "Choose"
        ' Make sure the filter list is clear
        .Filters.Clear
        ' Add two filters
        .Filters.Add "JPEGs", "*.jpg"
        '.Filters.Add "Bitmaps", "*.bmp"
        ' Set the filter index to 2
        .FilterIndex = 2
        ' Set the initial path name
        
        .InitialFileName = "B:\Dropbox\Business Documents\Database\Database Images\"
        
        
        ' Show files as thumbnails
        .InitialView = msoFileDialogViewThumbnail
        ' Show the dialog and test the return
        If .Show = 0 Then
            ' Didn't pick a file - bail
            Exit Sub
        End If
        ' Should be only one filename - grab it
        strPath = Trim(.SelectedItems(1))
                ' Set an error trap
        On Error Resume Next
        ' Set the image
        Me.txtImage = strPath
        ' Set the message in case Image control couldn't find it
        Me.lblMsg.Caption = "Failed to load the picture you selected." & _
            "  Click Add to try again."
    End With
    ' Put focus in a safe place
    Me.cmdCloseForm.SetFocus

End Sub

Open in new window

0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 39886674
Back in the old days, the B: drive was a floppy disk drive.  What is it on your computer?
0
 

Author Comment

by:SteveL13
ID: 39886778
Hard to believe but "B" is the hard drive on the computer.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39887510
Works for me as written, using a directory that exists on my own computer.  (Access 2010/Windows 7)

Double-check the path for spelling accuracy, spaces, etc and also verify that you have the needed permissions set on that folder.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39887524
Also take a look at this KB article for details about .InitialFileName:
http://msdn.microsoft.com/en-us/library/office/aa210656(v=office.11).aspx

If the specified value is invalid (typos, etc), the folder will default to the last used.  There also is a maximum length of 256 characters specified for valid file names.  The one you have posted is well within that limit, but just worth noting in case you are using longer file names in your production environment.
0
 

Author Closing Comment

by:SteveL13
ID: 39890368
Spelling gets me every time.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question