Solved

Command button not taking user to proper path

Posted on 2014-02-25
5
299 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
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

829 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