Solved

"Requires a file name" error

Posted on 2003-10-21
2
422 Views
Last Modified: 2013-12-26
I am using this code to allow the user to import a file into access:

Function TestIt3()
    Dim strFilter As String
    Dim strInputFileName As String
    strFilter = ahtAddFilterItem(strFilter, "CSV Files (*.csv)", "*.CSV")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
        strInputFileName = ahtCommonFileOpenSave( _
                Filter:=strFilter, OpenFile:=True, _
                DialogTitle:="Please select an import file...", _
                Flags:=ahtOFN_HIDEREADONLY)
        MsgBox "You selected: " & strInputFileName, (vbInformation), "Walklist Selection"
    Debug.Print Hex(IngFlags)
    Debug.Print strInputFileName
    DoCmd.TransferText acImportDelim, "Parameter Spec", "WalklistTemplate", strInputFileName, hasfieldnames - 1
End Function

It works perfectly, except for when you press the cancel button in the browse file dialog box.  Then it comes up with the error, "The action or method requires a file name argument."
This is because the DoCmd.TransferText action is looking for a file name, but because the user pressed cancel, it comes up with an error.  
Is there any way I can just make the cancel button work without coming up with an error message?

Thanks!
0
Comment
Question by:AndySinger
2 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 300 total points
ID: 9592319
Can't you check strInputFileName to see if it is empty?

if strInputFileName = "" Then Exit Function
0
 

Author Comment

by:AndySinger
ID: 9592465
yeah that worked, 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

12 Experts available now in Live!

Get 1:1 Help Now