Call a Public function within a module that uses "With"

I'm trying to call a public function using:
Call CreateRecordset(PrYTDSales, strPrYTDSales)


calling:

Public Function CreateRecordset(PassedRecordset As ADODB.Recordset, PassedString As String) As String
   
    With PassedRecordset
        .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .Open PassedString
    End With

End Function

Getting the error:
Expected variable or procedure, not module


The "With" is throwing me off.  Any ideas?

Thanks
bfitch01Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
I see.

you could have tried this:
CreateRecordset.CreateRecordset PrYTDSales, strPrYTDSales
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what are the names of your modules? if you have a module and function/variable that have the same name, this can give you this kind of compilation error....
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Public Function CreateRecordset(rsPassedRecordset As ADODB.Recordset, strPassedString As String) As String
   
    With rsPassedRecordset
        .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .Open strPassedString
    End With

End Function


and call:

CreateRecordset PrYTDSales, strPrYTDSales
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
bfitch01Author Commented:
They have the same name.  So how do I call a function within a module with different names?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what has the same names?
0
 
bfitch01Author Commented:
The function and the module were both called CreateRecordset, I changed the module to mdlCreateRecordset
0
 
bfitch01Author Commented:
Yeah, just figured that out.  Now I get arguments are of the wrong type, out of the acceptable range or in conflict with each other error.
0
 
bfitch01Author Commented:
I figured it out, I had to pass the adodb.connect (cn) along with the other parameters.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.