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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |