Solved

file dialog box not working correctly

Posted on 2011-09-14
11
352 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
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 119

Expert Comment

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

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

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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 …

910 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

23 Experts available now in Live!

Get 1:1 Help Now