using cmd button to call Sub-routine

  • Thread starter Thread starter Shawna
  • Start date Start date
S

Shawna

Hi there,

Can anyone shed some light on this....

My Sub-routine is declared as follows

Public Sub ImportFile(strPath As String)

The cmd button code is as follows

Private Sub Command5_Click()

On Error GoTo Err_cmdImport_Click

Dim strPath As String

strPath = "C:\5153.txt"

ImportFile (strPath)

Exit_cmdImport_Click:
Exit Sub

Err_cmdImport_Click:
MsgBox Err.description
Resume Exit_cmdImport_Click


End Sub

When I click the cmd button to run, I get Invalid
Argument msg and that's it.

Also, Dim db as Database, rs as Recordset fails to
compile, message is user-defined type not defined and the
cursor highlights db as Database? Any thoughts?

Thanks for help....

Shawna
 
change it to

ImportFile strPath

when calling a subroutine, you don't use parentheses
unless you use the word Call; or unless you call the
subroutine in an expression, for instance

If ImportFile(strPath) = False Then (etc, etc)

re the compile problem: you need to declare the db and
recordset types as DAO or ADO. if you don't know which
you're using, it's probably DAO. so try

Dim db as DAO.Database, rs as DAO.Recordset

if you're using Access 2000 (and possibly newer versions),
you need to set the DAO reference because A2K defaults to
ADO.

hth
 
Thanks for your help.

Regarding the compile problem I tried both DAO and
ADO.Database and both still resulted in the userdefined
type error? any ideas?
 
I had to check mark a refernce library under
Tools/Options Editor tab for Microsoft DAO 3.6 Library.
So it seems to recognize the delaration, but now when I
hit the cmd button I get a msg Invalid Procedure Call or
Argument?

Shawna
 
sounds like it's still unhappy with your procedure call,
but i don't see any error based on the info you originally
posted and my reply. did you step thru the code to see
exactly which line it's erring out on?
 
Thanks for your help, I stepped through and seemed to
solve that problem - of course new ones airse....
 
Back
Top