Link to home
Start Free TrialLog in
Avatar of AndySinger
AndySinger

asked on

"Requires a file name" error

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!
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AndySinger
AndySinger

ASKER

yeah that worked, thanks!!