Solved

file dialog box not working correctly

Posted on 2011-09-14
11
354 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36537224

...


     
     .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
ID: 36537504
no change after adding the line.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36537624
do a compact and repair of the db..

just tested the codes and it work ok.. in A2003
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:vmccune
ID: 36537699
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
ID: 36537796
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
 
LVL 120

Expert Comment

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

Author Comment

by:vmccune
ID: 36537820
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36537870
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
ID: 36538039
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36538167
sorry, change this
   
        Me.FileList = varFile


with


       Me.FileList = .selecteditems(1)
0
 

Author Closing Comment

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

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

828 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