Solved

File Picker error when user double clicks instead of pressing "OPEN"

Posted on 2006-06-29
4
273 Views
Last Modified: 2008-01-09
I have code (shown below) which allows user to select a data file which is then established as the "be" file for the main application.  Works fine if user chooses file name and then clicks "OPEN".  However, if user double clicks file name, the function completes but leaves the "be" file in an unreadable state.  I then have to open the "be" file directly and let Access correct it.  I can't seem to trap the error.
CODE:
Option Compare Database
Option Explicit
Public Function RetrieveArchive()
    ' Comments  :This function allows the user to select a 'specific' "_be.mdb" (data) file
                'and then copies that file to "C:\Program Files\SuperAudits"
    ' Parameters:
    ' Returns   :  -
    ' Created   : 01/06/06 09:07 RRS
    ' Modified  :
    '
    ' --------------------------------------------------

    'ErrorEnablerStart
On Error GoTo PROC_ERR
    'ErrorEnablerEnd
Dim strFilter As String
Dim strInputFileName As String
Dim strDestFileName As String
Dim vrtSelectedItem As Variant
Dim strFileName As Variant
Dim fs As FileSystemObject
Dim strSTATUS As String
Dim varSTATUS As Boolean
Dim vtext As String
Dim stdocname As String

DoCmd.Hourglass True
strSTATUS = "Retrieving Data, Please be patient"
varSTATUS = SysCmd(acSysCmdSetStatus, strSTATUS)
'initiate file dialog and allow user to choose
strFilter = ahtAddFilterItem(strFilter, "MDB Files (*.MDB)", "*.MDB")
strInputFileName = ahtCommonFileOpenSave( _
                InitialDir:="C:\SuperAudits", _
                Filter:=strFilter, OpenFile:=True, _
                DialogTitle:="Please select an input file...", _
                Flags:=ahtOFN_HIDEREADONLY)
'If user cancelled or closed the file dialog without picking a file,
'need to get out gracefully
If strInputFileName = "" Then
  MsgBox "You chose to cancel the file selection." & vbCr & _
        "If you wish to retrieve an archived data file, choose the file name and click OPEN."
  stdocname = "frm Selection Criteria"
  DoCmd.OpenForm stdocname, acNormal
  GoTo PROC_EXIT
End If

'define where to put the chosen file
strDestFileName = "c:\Program Files\SuperAudits\superaudits_be.mdb"

'copy the file to the chosen location
Set fs = CreateObject("Scripting.FileSystemObject")
 fs.CopyFile strInputFileName, "c:\Program Files\SuperAudits\", True
'tell the user it worked
varSTATUS = SysCmd(acSysCmdClearStatus)
DoCmd.OpenForm "frmOpenMain", acNormal

PROC_EXIT:
    DoCmd.Hourglass False
    Exit Function
'ErrorHandlerStart
PROC_ERR:
    MsgBox Err.Description
    Resume PROC_EXIT
   
End Function
0
Comment
Question by:Shelnutt
  • 2
  • 2
4 Comments
 
LVL 84
ID: 17013236
I would suspect that the code is attempting to open the file in question, instead of merely returning the filename .... this is a function of the filepicker, and you'll be hard pressed to trap the error (since there really is no error from your code, but instead a system error from MS Access).

You could instead try training the user - add a string to the DialogTitle: "SINGLE CLICK ONLY" ... not sure this would work, of course, since most users ignore the title ...

Perhaps a combination of various flags would help - the ahtCommonFile routine has many OFN flags which you can OR together:

.Flags=ahtOFN_HIDEREADONLY OR ahtOFN_PATHMUSTEXIST for example ... those wouldn't work, of course, but perhaps there is a combination which would tell the dialog to only return the filename and to NOT attempt to open/run the selected file ...
0
 

Author Comment

by:Shelnutt
ID: 17017293
Thank you for your quick response.  I will take a look at flags.  You are right, training users is really difficult.  That's why I am trying to trap all the ID10T errors.
0
 

Author Comment

by:Shelnutt
ID: 17018180
I believe I have solved the problem.  I am posting this for others (you never know who else might hit a snag).  I set the "OpenFile:" flag to False and the code seems to work with either a double click or using the "SAVE" button.  The only drawback (and I'm not sure it is) is that the dialog now says SAVE instead of OPEN.

Points should be awarded to LSMConsulting since they started me on the path to a resolution.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 total points
ID: 17019675
Hi Shelnutt,

Glad you got your problem solved. I wouldn't be too worried about what the file dialog button says, most people don't really pay much attention to it ... you can always hook the dialog and have the button say whatever you want, but this is quite troublesome and can lead to memory leaks and such.

You have to award the points. See here for information: http://www.experts-exchange.com/help.jsp#hs5
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
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 …

747 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

11 Experts available now in Live!

Get 1:1 Help Now