Solved

file dialog box not working correctly

Posted on 2011-09-14
11
355 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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