Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2008

Tip: Looking for answers? Try searching our database.

Form Reference

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DS - 22 May 2008 04:45 GMT
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
Tom van Stiphout - 22 May 2008 05:26 GMT
Is there a problem with having this function take two extra
parameters, a form object and a table object?

-Tom.

>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.
[quoted text clipped - 8 lines]
>Thanks
>DS
DS - 22 May 2008 05:44 GMT
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
DS - 22 May 2008 05:48 GMT
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
Tom van Stiphout - 22 May 2008 14:39 GMT
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.

>Like This?  Still trying to set variables though.
>
[quoted text clipped - 8 lines]
>Thanks
>DS
DS - 22 May 2008 16:28 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.