Solved

file dialog box not working correctly

Posted on 2011-09-14
11
350 Views
Last Modified: 2012-05-12
I am using the following code to find a source file to load into my application.  I need to find and selelct the dialog twice for it to work.  as an example:

If I select file "A" and load it when I first open the form, no problem.  If I then select file "B" and load, it loads file "A" even though file "B" is displayed in the dialog.  If I search and select for file "B" a second time, it then correclty loads file "B".  

My guess is somehow I need to refresh something internal to know what file I have selected.

Any help is appreciated.
Private Sub FileList_DblClick(Cancel As Integer)
' Requires reference to Microsoft Office 12.0 Object Library. '
   Dim fDialog As Office.FileDialog
   Dim varFile As Variant

   ' Clear listbox contents. '
   Me.FileList.RowSource = ""

   ' Set up the File Dialog. '
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

   With fDialog

      ' Allow user to make multiple selections in dialog box '
      .AllowMultiSelect = False

      ' Set the title of the dialog box. '
      .Title = "PROFITABILITY UPLOAD"

      ' Clear out the current filters, and add our own.'
      .Filters.Clear
      '.Filters.Add "Access Databases", "*.MDB"
      '.Filters.Add "Access Projects", "*.ADP"
      '.Filters.Add "All Files", "*.*"
      .Filters.Add "All Files", "*.csv"

      ' Show the dialog box. If the .Show method returns True, the '
      ' user picked at least one file. If the .Show method returns '
      ' False, the user clicked Cancel. '
      If .Show = True Then
        

         'Loop through each file selected and add it to our list box. '
         For Each varFile In .SelectedItems
            Me.FileList.AddItem varFile
         Next

      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With

End Sub

Open in new window

0
Comment
Question by:vmccune
  • 6
  • 5
11 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility

...


     
     .InitialFileName=""           'ADD this line
      .Filters.Clear
      '.Filters.Add "Access Databases", "*.MDB"
      '.Filters.Add "Access Projects", "*.ADP"
      '.Filters.Add "All Files", "*.*"
      .Filters.Add "All Files", "*.csv"

0
 

Author Comment

by:vmccune
Comment Utility
no change after adding the line.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
do a compact and repair of the db..

just tested the codes and it work ok.. in A2003
0
 

Author Comment

by:vmccune
Comment Utility
still no change in 2007.

I also tried requering this box from the command button before I import the file.  No help.
0
 

Author Comment

by:vmccune
Comment Utility
I saved this in 2003 to test.

When the form opens the text box is pointing to a file on C that is no longer there.  If I double click to browse to the correct file and try to load, it tells me the non existant file cannot be found.  If I double click and browse again, the file loads.  Again it takes two time to set it to the correct file location.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
can you create a .MDB (not convert), then import the objects from your db and upload the .MDB
0
 

Author Comment

by:vmccune
Comment Utility
I did this as a list box as that was the example I found.  Could it have any bearing or would it help to change it to a text box?
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
if you only want a single item display in a textbox, you can do this


     If .Show = True Then
       
          me.textbox=varFile

         'Loop through each file selected and add it to our list box. '
 '        For Each varFile In .SelectedItems
 '           Me.FileList.AddItem varFile
 '        Next

      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
0
 

Author Comment

by:vmccune
Comment Utility
Ok. I changed it to a text box and this is the new code.  It now does not display the file name after I double click.  Maybe this is a symptom on the same problem?
Private Sub FileList_DblClick(Cancel As Integer)
' Requires reference to Microsoft Office 12.0 Object Library. '
   Dim fDialog As Office.FileDialog
   Dim varFile As Variant

   ' Clear listbox contents. '
   ''Me.FileList.RowSource = ""

   ' Set up the File Dialog. '
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

   With fDialog

      ' Allow user to make multiple selections in dialog box '
      '.AllowMultiSelect = False

      ' Set the title of the dialog box. '
      .Title = "PROFITABILITY UPLOAD"

      ' Clear out the current filters, and add our own.'
      .Filters.Clear
      '.Filters.Add "Access Databases", "*.MDB"
      '.Filters.Add "Access Projects", "*.ADP"
      '.Filters.Add "All Files", "*.*"
      .Filters.Add "All Files", "*.csv"

      ' Show the dialog box. If the .Show method returns True, the '
      ' user picked at least one file. If the .Show method returns '
          If .Show = True Then
        
          Me.FileList = varFile

         'Loop through each file selected and add it to our list box. '
 '        For Each varFile In .SelectedItems
 '           Me.FileList.AddItem varFile
 '        Next

      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If

   End With

End Sub

Open in new window

0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
sorry, change this
   
        Me.FileList = varFile


with


       Me.FileList = .selecteditems(1)
0
 

Author Closing Comment

by:vmccune
Comment Utility
all set.  maybe something with being a list box.  Anyhow, all set.  Thanks,.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…

763 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

10 Experts available now in Live!

Get 1:1 Help Now