Form Reference

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
 
T

Tom van Stiphout

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.
 
D

DS

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
 
D

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
 
T

Tom van Stiphout

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.
 
D

DS

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Function Returns 0 3
Argument Not Optional 3
Line Break 9
Using INT() 5
Union Query Format 6
Not returning a value 8
SQL ORDER BY 1
DSum Problem 2

Top