Form Reference

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have a function where I want the table and the form to be able to change
as needed. I don't want to write a new function for each table and or form.

Public Function NODIS(CDQuantity As Integer, CDPrice As Currency, CDCheckID
As Integer, CDDiscountDP As Integer) As Currency
NODIS = Round(Nz(DSum("(CDQuantity*CDPrice)", "tblCheckDetailsTMP",
"CDCheckID = " & Forms!frmCheckAction!TxtCheckID & " AND CDDiscountDP = 0"),
0), 2)
End Function

Thanks
DS
 
On Wed, 21 May 2008 23:45:49 -0400, "DS" <[email protected]>
wrote:

Is there a problem with having this function take two extra
parameters, a form object and a table object?

-Tom.
 
OK Tom, Now I'm Lost. Could you show me? Also how do I set the table and
form varaibles when I call this function from the form?
Thanks
DS
 
Like This? Still trying to set variables though.

Public Function NOEX(CDQuantity As Integer, CDPrice As Currency, CDCheckID
As Integer, _
CDDiscountDP As Integer, strForm As Form, strTable As TableDef) As
Currency
NOEX = Round(Nz(DSum("(CDQuantity*CDPrice)", "strTable", "CDCheckID = "
& Forms!strForm!TxtCheckID & " AND CDDiscountDP = 0"), 0), 2)
End Function

Thanks
DS
 
On Thu, 22 May 2008 00:48:35 -0400, "DS" <[email protected]>
wrote:

You're warm, but a form object is not a string.
function f(frm as form, tbl as dao.tabledef)
x = DSum("SomeField", tbl.Name, "Somefield=" & frm!SomeControl.Value)

Call this from for example a button_click event:
x = f(Me, Currentdb.Tabledefs("SomeTable"))

Of course this would imply that you can call f only with forms that
have SomeControl as a control name. If the control name varies, pass
in a control object rather than a form object.

-Tom.
 
Thanks, Lifes getting better. The control name is always the same, it's only
the form and the table that changes. This works though.

The Function

Public Function BIG (frm as form, tbl as dao.tabledef)
BIG = DSum("Price", tbl.Name, "PriceID=" & frm!SomeControl.Value)
End Fuction

Calling it from the On Click of a list box.

Me.Text0 =BIG(Me, Currentdb.Tabledefs("tblPrices"))

Once again,
Thank You
DS
 
Back
Top