Solved

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

Posted on 2006-06-12
8
202 Views
Last Modified: 2010-04-07
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
0
Comment
Question by:bfitch01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16889094
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16889097
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
 

Author Comment

by:bfitch01
ID: 16889133
They have the same name.  So how do I call a function within a module with different names?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16889162
what has the same names?
0
 

Author Comment

by:bfitch01
ID: 16889180
The function and the module were both called CreateRecordset, I changed the module to mdlCreateRecordset
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 16889200
I see.

you could have tried this:
CreateRecordset.CreateRecordset PrYTDSales, strPrYTDSales
0
 

Author Comment

by:bfitch01
ID: 16889228
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
 

Author Comment

by:bfitch01
ID: 16889278
I figured it out, I had to pass the adodb.connect (cn) along with the other parameters.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month6 days, 7 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question