PC Review


Reply
Thread Tools Rate Thread

Calling a function (module) from code

 
 
=?Utf-8?B?RG9yY2k=?=
Guest
Posts: n/a
 
      15th May 2006
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."

 
Reply With Quote
 
 
 
 
Lynn Trapp
Guest
Posts: n/a
 
      15th May 2006
Try simply calling your function.

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


--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Access Junkie List:
http://home.bendbroadband.com/conrad...essjunkie.html



"Dorci" <(E-Mail Removed)> wrote in message
news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
> 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."
>



 
Reply With Quote
 
=?Utf-8?B?RG9yY2k=?=
Guest
Posts: n/a
 
      16th May 2006
When I do that, I get an error message:
Compile error: Unexpected: =


"Lynn Trapp" wrote:

> Try simply calling your function.
>
> MsgBox "ready to import"
> ItemImport()
> MsgBox "Returned from the Import function."
>
>
> --
> Lynn Trapp
> MS Access MVP
> www.ltcomputerdesigns.com
> Access Security: www.ltcomputerdesigns.com/Security.htm
> Jeff Conrad's Access Junkie List:
> http://home.bendbroadband.com/conrad...essjunkie.html
>
>
>
> "Dorci" <(E-Mail Removed)> wrote in message
> news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
> > 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."
> >

>
>
>

 
Reply With Quote
 
Lynn Trapp
Guest
Posts: n/a
 
      17th May 2006
Well, silly me. A function requires an assignment statement. You should
change your code to a procedure.

--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm
Jeff Conrad's Access Junkie List:
http://home.bendbroadband.com/conrad...essjunkie.html



"Dorci" <(E-Mail Removed)> wrote in message
news:5A9822F0-F528-4387-AAA4-(E-Mail Removed)...
> When I do that, I get an error message:
> Compile error: Unexpected: =
>
>
> "Lynn Trapp" wrote:
>
>> Try simply calling your function.
>>
>> MsgBox "ready to import"
>> ItemImport()
>> MsgBox "Returned from the Import function."
>>
>>
>> --
>> Lynn Trapp
>> MS Access MVP
>> www.ltcomputerdesigns.com
>> Access Security: www.ltcomputerdesigns.com/Security.htm
>> Jeff Conrad's Access Junkie List:
>> http://home.bendbroadband.com/conrad...essjunkie.html
>>
>>
>>
>> "Dorci" <(E-Mail Removed)> wrote in message
>> news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
>> > 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."
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?RG9yY2k=?=
Guest
Posts: n/a
 
      17th May 2006
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."


"Lynn Trapp" wrote:

> Well, silly me. A function requires an assignment statement. You should
> change your code to a procedure.
>
> --
> Lynn Trapp
> MS Access MVP
> www.ltcomputerdesigns.com
> Access Security: www.ltcomputerdesigns.com/Security.htm
> Jeff Conrad's Access Junkie List:
> http://home.bendbroadband.com/conrad...essjunkie.html
>
>
>
> "Dorci" <(E-Mail Removed)> wrote in message
> news:5A9822F0-F528-4387-AAA4-(E-Mail Removed)...
> > When I do that, I get an error message:
> > Compile error: Unexpected: =
> >
> >
> > "Lynn Trapp" wrote:
> >
> >> Try simply calling your function.
> >>
> >> MsgBox "ready to import"
> >> ItemImport()
> >> MsgBox "Returned from the Import function."
> >>
> >>
> >> --
> >> Lynn Trapp
> >> MS Access MVP
> >> www.ltcomputerdesigns.com
> >> Access Security: www.ltcomputerdesigns.com/Security.htm
> >> Jeff Conrad's Access Junkie List:
> >> http://home.bendbroadband.com/conrad...essjunkie.html
> >>
> >>
> >>
> >> "Dorci" <(E-Mail Removed)> wrote in message
> >> news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
> >> > 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."
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Douglas J Steele
Guest
Posts: n/a
 
      17th May 2006
EIther that, or use the Call keyword.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Lynn Trapp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Well, silly me. A function requires an assignment statement. You should
> change your code to a procedure.
>
> --
> Lynn Trapp
> MS Access MVP
> www.ltcomputerdesigns.com
> Access Security: www.ltcomputerdesigns.com/Security.htm
> Jeff Conrad's Access Junkie List:
> http://home.bendbroadband.com/conrad...essjunkie.html
>
>
>
> "Dorci" <(E-Mail Removed)> wrote in message
> news:5A9822F0-F528-4387-AAA4-(E-Mail Removed)...
> > When I do that, I get an error message:
> > Compile error: Unexpected: =
> >
> >
> > "Lynn Trapp" wrote:
> >
> >> Try simply calling your function.
> >>
> >> MsgBox "ready to import"
> >> ItemImport()
> >> MsgBox "Returned from the Import function."
> >>
> >>
> >> --
> >> Lynn Trapp
> >> MS Access MVP
> >> www.ltcomputerdesigns.com
> >> Access Security: www.ltcomputerdesigns.com/Security.htm
> >> Jeff Conrad's Access Junkie List:
> >> http://home.bendbroadband.com/conrad...essjunkie.html
> >>
> >>
> >>
> >> "Dorci" <(E-Mail Removed)> wrote in message
> >> news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
> >> > 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."
> >> >
> >>
> >>
> >>

>
>



 
Reply With Quote
 
Douglas J Steele
Guest
Posts: n/a
 
      17th May 2006
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."


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Dorci" <(E-Mail Removed)> wrote in message
news:C34BED19-3DD3-4203-B82A-(E-Mail Removed)...
> 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."
>
>
> "Lynn Trapp" wrote:
>
> > Well, silly me. A function requires an assignment statement. You should
> > change your code to a procedure.
> >
> > --
> > Lynn Trapp
> > MS Access MVP
> > www.ltcomputerdesigns.com
> > Access Security: www.ltcomputerdesigns.com/Security.htm
> > Jeff Conrad's Access Junkie List:
> > http://home.bendbroadband.com/conrad...essjunkie.html
> >
> >
> >
> > "Dorci" <(E-Mail Removed)> wrote in message
> > news:5A9822F0-F528-4387-AAA4-(E-Mail Removed)...
> > > When I do that, I get an error message:
> > > Compile error: Unexpected: =
> > >
> > >
> > > "Lynn Trapp" wrote:
> > >
> > >> Try simply calling your function.
> > >>
> > >> MsgBox "ready to import"
> > >> ItemImport()
> > >> MsgBox "Returned from the Import function."
> > >>
> > >>
> > >> --
> > >> Lynn Trapp
> > >> MS Access MVP
> > >> www.ltcomputerdesigns.com
> > >> Access Security: www.ltcomputerdesigns.com/Security.htm
> > >> Jeff Conrad's Access Junkie List:
> > >> http://home.bendbroadband.com/conrad...essjunkie.html
> > >>
> > >>
> > >>
> > >> "Dorci" <(E-Mail Removed)> wrote in message
> > >> news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
> > >> > 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."
> > >> >
> > >>
> > >>
> > >>

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?RG9yY2k=?=
Guest
Posts: n/a
 
      18th May 2006
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.

"Douglas J Steele" wrote:

> EIther that, or use the Call keyword.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Lynn Trapp" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Well, silly me. A function requires an assignment statement. You should
> > change your code to a procedure.
> >
> > --
> > Lynn Trapp
> > MS Access MVP
> > www.ltcomputerdesigns.com
> > Access Security: www.ltcomputerdesigns.com/Security.htm
> > Jeff Conrad's Access Junkie List:
> > http://home.bendbroadband.com/conrad...essjunkie.html
> >
> >
> >
> > "Dorci" <(E-Mail Removed)> wrote in message
> > news:5A9822F0-F528-4387-AAA4-(E-Mail Removed)...
> > > When I do that, I get an error message:
> > > Compile error: Unexpected: =
> > >
> > >
> > > "Lynn Trapp" wrote:
> > >
> > >> Try simply calling your function.
> > >>
> > >> MsgBox "ready to import"
> > >> ItemImport()
> > >> MsgBox "Returned from the Import function."
> > >>
> > >>
> > >> --
> > >> Lynn Trapp
> > >> MS Access MVP
> > >> www.ltcomputerdesigns.com
> > >> Access Security: www.ltcomputerdesigns.com/Security.htm
> > >> Jeff Conrad's Access Junkie List:
> > >> http://home.bendbroadband.com/conrad...essjunkie.html
> > >>
> > >>
> > >>
> > >> "Dorci" <(E-Mail Removed)> wrote in message
> > >> news:64E8C3E3-B1E3-4202-9171-(E-Mail Removed)...
> > >> > 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."
> > >> >
> > >>
> > >>
> > >>

> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Module function in query =?Utf-8?B?SGl0ZXNoIENoYXVoYW4=?= Microsoft Access VBA Modules 4 14th Nov 2007 02:17 PM
Calling a function in another module =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 4 7th Nov 2006 03:16 PM
calling a module function =?Utf-8?B?SGxld2lz?= Microsoft Access Form Coding 5 23rd Mar 2006 08:33 PM
calling module function from macro =?Utf-8?B?VE1HcmVlbg==?= Microsoft Access Macros 3 8th Mar 2006 12:17 AM
Calling VBA function that is in another module Jag Man Microsoft Excel Programming 2 7th Jan 2004 03:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.