Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

file dialog box not working correctly

Posted on 2011-09-14
11
Medium Priority
?
358 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 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