?
Solved

"Requires a file name" error

Posted on 2003-10-21
2
Medium Priority
?
429 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
[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
2 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 1200 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

Independent Software Vendors: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 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