Solved

"Requires a file name" error

Posted on 2003-10-21
2
418 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
Comment Utility
Can't you check strInputFileName to see if it is empty?

if strInputFileName = "" Then Exit Function
0
 

Author Comment

by:AndySinger
Comment Utility
yeah that worked, thanks!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

10 Experts available now in Live!

Get 1:1 Help Now