Calling a function (module) from code

D

Dorci

Access 2003 - I have a module function that works just fine when I call it
from a macro (using the RunCode action). However, when I call it from code,
some screens splash by quickly, then the code moves on to the next step.
Adding Msgboxes to the function didn't even slow it down to let me see what's
happening. Any ideas?

HERE'S THE FUNCTION:

Function ItemImport()
Dim strFilter As String
Dim strInputFileName As String

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

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97,
"tblItemImport", strInputFileName, True

End Function

HERE'S THE CALL:

MsgBox "ready to import"
DoCmd.OpenModule "modItemImport"
MsgBox "Returned from the Import function."
 
D

Dorci

Lynn,
Thanks for bearing with me. I made the following changes with the same
result. The program appears to skip right over the procedure. Maybe I
totally misunderstood your instruction.

HERE'S THE FUNCTION:

Sub ItemImport
Dim strFilter As String
Dim strInputFileName As String

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

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97,
"tblItemImport", strInputFileName, True

End Sub

HERE'S THE CALL:

MsgBox "ready to import"
DoCmd.OpenModule "modItemImport"
MsgBox "Returned from the Import function."
 
D

Douglas J Steele

The name of the module to which your stored the routine is immaterial (as
long as it's not the same as the routine!) The name of your sub is
ItemImport: that's what you should be calling

MsgBox "ready to import"
Call ItemImport()
MsgBox "Returned from the Import function."
 
D

Dorci

Thanks guys! Earlier today, I just copied the procedure code directly into
the program code, since it was only a few lines. I may try your last
suggestions if I later discover that was a bad idea. Thanks as always for
your help.
 

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