Browse File and Import Into Access

  • Thread starter Tony H. via AccessMonster.com
  • Start date
T

Tony H. via AccessMonster.com

I have a menu item to import data from an Excel file. I want the user to
browse for the file and import the file into Access which appends to the
tblMaster.

First, I copied the code by Ken Getz -
http://www.mvps.org/access/api/api0001.htm into a module named “BrowseFile”.
Then in another module named “import” I have the code below. In the menu
Item properties I have “=ImportEx()” in the on Action property. But when I
click on the menu I get an error “Ambiguous name ahtAddFilterItem”

Can anyone tell me what I’m doing wrong? Here’s my code…….


Public Function ImportEx()

Dim strFilter As String
Dim lngFlags As Long
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
Debug.Print Hex(lngFlags)

strInputFileName = ahtCommonFileOpenSave(InitialDir:=C:\", _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "tblMaster", ,
strInputFileName, True, ""

End Function

Thanks,
Tony
 
D

Douglas J Steele

The error message implies that you have 2 (or more) declarations for
ahtAddFilterItem in your application.

You didn't happen to already have the code in your application, did you?

Do a Find on ahtAddFilterItem.
 
S

SusanV

Ambiguous name indicates that you have more than one function with the same
name. Find the duplicate and either remove it or rename it.
 
T

Tony H. via AccessMonster.com

Thanks Douglas. I found the duplicate declaration. But not I'm receiving
the error that it requires a file name argument... I was expecting the
browse to insert the file name for the import. Please help.

Here's my code:



Public Function ImportEx()

Dim strFilter As String
Dim lngFlags As Long
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
Debug.Print Hex(lngFlags)


strInputFileName = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)


DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8,
"tblProspectProfile", , , True


End Function
The error message implies that you have 2 (or more) declarations for
ahtAddFilterItem in your application.

You didn't happen to already have the code in your application, did you?

Do a Find on ahtAddFilterItem.
I have a menu item to import data from an Excel file. I want the user to
browse for the file and import the file into Access which appends to the
tblMaster.

First, I copied the code by Ken Getz -
http://www.mvps.org/access/api/api0001.htm into a module named “BrowseFile”.
Then in another module named “import” I have the code below. In the menu
Item properties I have “=ImportEx()” in the on Action property. But when I
[quoted text clipped - 23 lines]
Thanks,
Tony
 
D

Douglas J Steele

The file you selected in the dialog is stored in strInputFileName

You must include that variable in your TransferSpreadsheet statement:

DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel8, _
"tblProspectProfile", strInputFileName, True


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Tony H. via AccessMonster.com said:
Thanks Douglas. I found the duplicate declaration. But not I'm receiving
the error that it requires a file name argument... I was expecting the
browse to insert the file name for the import. Please help.

Here's my code:



Public Function ImportEx()

Dim strFilter As String
Dim lngFlags As Long
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
Debug.Print Hex(lngFlags)


strInputFileName = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)


DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8,
"tblProspectProfile", , , True


End Function
The error message implies that you have 2 (or more) declarations for
ahtAddFilterItem in your application.

You didn't happen to already have the code in your application, did you?

Do a Find on ahtAddFilterItem.
I have a menu item to import data from an Excel file. I want the user to
browse for the file and import the file into Access which appends to the
tblMaster.

First, I copied the code by Ken Getz -
http://www.mvps.org/access/api/api0001.htm into a module named “BrowseFile”.
Then in another module named “import” I have the code below. In the menu
Item properties I have “=ImportEx()” in the on Action property. But
when I
[quoted text clipped - 23 lines]
Thanks,
Tony
 

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