Solved

Command button not taking user to proper path

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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 …
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now