?
Solved

Command button not taking user to proper path

Posted on 2014-02-25
5
Medium Priority
?
305 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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

765 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