Solved

Command button not taking user to proper path

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

733 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