Code to skip transferspreadsheet if file open dialog box is cancel

G

Guest

Hi Again. I need VBA code to jump over my transferspreasheet function if I
click cancel instead of open from my open file dialog box logic i got from
you guys.

Private Sub cmdImportAIM_Click()
Dim strFilter As String
Dim strInputFileName As String
Dim age As Date


strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)",
"*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)

'Need error handling if I cancel open file
DoCmd.TransferSpreadsheet acImport, 8, "tblAIMFund",
strInputFileName, True

End Sub

Also, Do you know how my file open requirements can be a little more
specific if i want only file names that end in " * template.xls"


--
(I can't express enough gratitude to everyone who spends time answering our
questions!)

Thanks,
Matt
(access 2000)
 
D

Douglas J. Steele

To check for Cancel:

If Len(strInputFileName) = 0 Then
' Cancel was selected
Else
' do your stuff..
End If

To restrict your lookup:

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)",
"*template.XLS")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top