A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Passing Recordset of Form to Function



 
 
Thread Tools Display Modes
  #1  
Old June 14th, 2006, 03:13 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Passing Recordset of Form to Function

I have a function declared as:
Public Function F_CalculateSales(rst As Recordset, Week_ID As Integer,
Sales_ID As Integer) As Single

I am trying to have a field on a form with the expression:
=F_CalculateSales(Me.Recordset,[fk_Week_ID],[fk_Sales_ID])
also tried
=F_CalculateSales(Me.RecordsetClone,[fk_Week_ID],[fk_Sales_ID])

This is producing a #Name error, i seem to be unable to pass the recordset
to that public function.

I also tried
=F_CalculateSales(Forms![SalesForm].Recordset,[fk_Week_ID],[fk_Sales_ID])
also tried
=F_CalculateSales(Forms![SalesForm].RecordsetClone,[fk_Week_ID],[fk_Sales_ID])

Which is asking me for the value of Recordset or RecordsetClone...

I would like to be able to pass the recordset from the form containing that
field to this function. Is there any way to do that?

I could open a new recordset within the function with the same query, but
that will evaluate for every row and be extremely non-optimized.

Thanks,
-Ben
  #2  
Old June 14th, 2006, 04:18 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Passing Recordset of Form to Function

Create a function in the form that will pass the parameters to the global
function, and call this function from the text box

Text Box
=NewFunctionName()

Function NewFunctionName()
Dim Rs as RecordSet
Set Rs = Me.RecordsetClone
NewFunctionName = F_CalculateSales(Rs,Me.[fk_Week_ID],Me.[fk_Sales_ID])
End Function

Note: I didn't try it, but it's an idea
--
Good Luck
BS"D


"BenWeber" wrote:

I have a function declared as:
Public Function F_CalculateSales(rst As Recordset, Week_ID As Integer,
Sales_ID As Integer) As Single

I am trying to have a field on a form with the expression:
=F_CalculateSales(Me.Recordset,[fk_Week_ID],[fk_Sales_ID])
also tried
=F_CalculateSales(Me.RecordsetClone,[fk_Week_ID],[fk_Sales_ID])

This is producing a #Name error, i seem to be unable to pass the recordset
to that public function.

I also tried
=F_CalculateSales(Forms![SalesForm].Recordset,[fk_Week_ID],[fk_Sales_ID])
also tried
=F_CalculateSales(Forms![SalesForm].RecordsetClone,[fk_Week_ID],[fk_Sales_ID])

Which is asking me for the value of Recordset or RecordsetClone...

I would like to be able to pass the recordset from the form containing that
field to this function. Is there any way to do that?

I could open a new recordset within the function with the same query, but
that will evaluate for every row and be extremely non-optimized.

Thanks,
-Ben

  #3  
Old June 14th, 2006, 04:26 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Passing Recordset of Form to Function

You might try using the OnCurrent Event for the form.

There you could put
Me.YourFieldName = F_CalculateSales(Me.RecordSource, Me.[fk_Week_ID],
Me.fk_Sales_ID])

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call data collection form from Function and wait till form close t dkern General Discussion 1 February 27th, 2006 03:36 AM
Attaching Code DS General Discussion 2 August 22nd, 2005 11:21 PM
Requerying a pop up form to display in the main form Jennifer P Using Forms 13 April 5th, 2005 06:59 PM
Design help, please SillySally Using Forms 27 March 6th, 2005 04:11 AM
Strange stLinkCriteria behaviour on command button Anthony Dowd Using Forms 3 August 21st, 2004 03:01 AM


All times are GMT +1. The time now is 02:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.