Solved

"Requires a file name" error

Posted on 2003-10-21
2
427 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 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

Industry Leaders: 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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

732 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