Connecting Tech Pros Worldwide Help | Site Map

Default Value from Module

Newbie
 
Join Date: Aug 2009
Posts: 22
#1: 4 Weeks Ago
Hi I need help to clean up my module usage and to use it to bring up a deafult value for a field.

My Module that works fine when used as code in a form
Expand|Select|Wrap|Line Numbers
  1. Public Function mgmtRateCheck(StartDate, ConfirmRate)
  2.  
  3. Dim Rate1 As Double
  4. Dim DMonth As String
  5.  
  6.     DMonth = month(StartDate) & "/" & Day(StartDate) & "/" & Year(StartDate)
  7.  
  8.     Rate1 = 0
  9.  
  10.     Rate1 = DLookup("mgmtRate", "tblmgmtRate", _
  11.     "RateDateStart <= #" & DMonth & "#" & " And RateDateEnd >= #" & DMonth & "#")
  12.  
  13.     ConfirmRate = Rate1
  14.  
  15. End Function
  16.  
this is how I use it in a form and it works fine
Expand|Select|Wrap|Line Numbers
  1. Call mgmtRateCheck(Date, ConfirmmgmtRate)
  2. Me.mgmtFee = ConfirmmgmtRate
  3.  
How do I utilise it as a Default Value function for a field on a form.

Thanks
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,213
#2: 4 Weeks Ago

re: Default Value from Module


Quote:

Originally Posted by tasawer View Post

Hi I need help to clean up my module usage and to use it to bring up a deafult value for a field.

My Module that works fine when used as code in a form

Expand|Select|Wrap|Line Numbers
  1. Public Function mgmtRateCheck(StartDate, ConfirmRate)
  2.  
  3. Dim Rate1 As Double
  4. Dim DMonth As String
  5.  
  6.     DMonth = month(StartDate) & "/" & Day(StartDate) & "/" & Year(StartDate)
  7.  
  8.     Rate1 = 0
  9.  
  10.     Rate1 = DLookup("mgmtRate", "tblmgmtRate", _
  11.     "RateDateStart <= #" & DMonth & "#" & " And RateDateEnd >= #" & DMonth & "#")
  12.  
  13.     ConfirmRate = Rate1
  14.  
  15. End Function
  16.  
this is how I use it in a form and it works fine
Expand|Select|Wrap|Line Numbers
  1. Call mgmtRateCheck(Date, ConfirmmgmtRate)
  2. Me.mgmtFee = ConfirmmgmtRate
  3.  
How do I utilise it as a Default Value function for a field on a form.

Thanks

Unless I am way off base on this one, you are:
  1. Passing the Current Date to the Function.
  2. Rebuilding the Current Date within the Function.
  3. Retrieving the Return Value from the Function via one of its Arguments.
  4. If this is all correct, then the Function can be simplified to:
    Expand|Select|Wrap|Line Numbers
    1. Public Function mgmtRateCheck()
    2. Dim Rate1 As Double
    3.  
    4. Rate1 = 0
    5.  
    6. Rate1 = DLookup("mgmtRate", "tblmgmtRate", _
    7.         "RateDateStart <= #" & Date & "#" & " And RateDateEnd >= #" & Date & "#")
    8.  
    9. mgmtRateCheck = Rate1
    10. End Function
  5. To Set the Default Value of a Form Field (Text Box) equal to the return Value of this Function, set its Default Value (Properties ==> Data Tab ==> Default Value) equal to:
    Expand|Select|Wrap|Line Numbers
    1. =mgmtRateCheck()
Newbie
 
Join Date: Aug 2009
Posts: 22
#3: 4 Weeks Ago

re: Default Value from Module


Hi Adezzi, we are partly there.
This is one solves the default value for me. Thx

In the 'tblmgmgrate', I have managment rate fixed between two dates.
I need to pick the rate according the invoice date

When an invoice is created, it gets current date as invoice date and mgmtrate can default to your solution above.

However, when entering a backlog of invoices, InvoiceDate will be entered manually hence the need to re-select mgmtrate.

I hope this makes sense.

Regards
Reply