Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid use of property error message

Status
Not open for further replies.

TLiberty

Programmer
Nov 22, 1999
27
US
Case Definition:<br>
I have a class module in which it is to generate a report from several databases based on a criterion passed to the class during initialization. The criterion could be a Global Report of only sub totals or a detailed report. <br>
<br>
Problem:<br>
When I want to return the actual recordset created by the class module it gives me an &quot;Invalid use of property&quot; compile error message. And actually I'm using a method to return the recordset. <br>
<br>
Code:<br>
'Several code up here, initialization of class etc.<br>
'The class returns a recordset<br>
Set TDF = clsSource.SetRecordset.Clone<br>
'Error occurs during the execution of the above stmnt.<br>
...<br>
'End of calling code<br>
<br>
'Class code<br>
Public Function SetRecordset() As Recordset<br>
On error goto errSetRecordset<br>
<br>
SetRecordset = rsTDF 'Class recordset containing results<br>
Exit Function<br>
<br>
errSetRecordset:<br>
MsgBox err.Number & &quot; &quot; & err.Description<br>
Exit Function<br>
End Function
 
You can't use certain properties in a Sub or Function in a Module because the Form in not in your Module.<br>
Such as Recordset Clone<br>
You have to write out code explicitly to get the recordset.<br>
---------------<br>
Dim db as database, rst as recordset, SQL as string<br>
Set db = CurrentDb<br>
' SQL string.<br>
SQL = &quot;SELECT * FROM Orders WHERE OrderDate &gt;= #1-1-95#;&quot;<br>
Set rst = db.OpenRecordset(SQL)<br>
---------------------<br>
<br>
See the recordset is attached to your form<br>
I think that's your problem but can't tell from your short amount of code.<br>

 
Understand &quot;can't use certain properties in a module because the form is not in my module.&quot; Let me elaborate more explicitly on the situtation. I have a form that requires the user to select information as below:<br>
<br>
Global 'Aggregate totals per sources<br>
------<br>
Interface:<br>
Beginning Date: / /<br>
Ending Date: / /<br>
<br>
Detailed <br>
--------<br>
Listbox containing sources where user can select multiple areas.<br>
Beginning Date: / /<br>
Ending Date: / /<br>
<br>
Where does class module fits in?<br>
--------------------------------<br>
The class takes the user input and evaluates the user request and returns a resultset containing the information the user wants and has totals that the user can just request by selecting an appropriate property. Therefore, the object interface is as follow:<br>
<br>
Properties GET (No LET required for this class)<br>
-----------------------------------------------<br>
RetTestedTotal 'Returns total amount tested per source<br>
Ret... 'Several properties that return totals/src<br>
<br>
Methods<br>
-------<br>
SetReportType 'Used to indicate if Global/Detailed<br>
SQLProcess 'Based on the user request (Global/Detail)<br>
'this method instantiates the recordset and<br>
'uses the appropriate SQL statement to <br>
'generate a result and store totals (grand)<br>
'in the appropriate properties<br>
All that is requested from the user in this method is the Beginning and ending date. Based on how the SetReportType method was used the SQLProcess method can determine what result set to return and what totals to place in properties.<br>
Therefore, as you can see there is no reason to let the user generate another SQL statement outside of the class interface, it would be appropriate to return the recordset to the user and let him or her use it to gather what information he would like. [The main reason of having a class module to do this is because there are all sorts of information that can be gather from a single result set - be it Global or Detailed - and the user uses the aggregate or grand totals to perform other calculations in several forms. See the hassle]<br>
<br>
'Thus lead us to our major method<br>
SetTableClone 'Which returns the recordset to the outside<br>
'world - used in the expression above <br>
'Set rs = clsSource.SetTableClone.Clone<br>
<br>
No Events necessary since almost everything should be manageable by the class.<br>
<br>
Back on track.<br>
-------------<br>
In your post, DougP, that I can not return a recordset from the method SetTableClone. Because, if that is the case then there is no need creating this object - if I'm to allow the user to manipulate the information. Let him do it instead of me (know what I mean!)<br>

 
You can still create the object but you cannot use the statement RECORDSET CLONE<br>
BECAUSE it is NOT in that FORM<br>
click HELP and type in CLASS. The definition of a CLASS is something outside of a form or report<br>
SO therefore you cannot set something to something that is outside<br>
It is separate<br>
But to finish your project and move on <br>
Create a Code procedure that opens the TABLE where your FORM is attached and get the same result using the code example in my previous post<br>
If you want to use Recordset clone put the code in a command button which is on the form.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top