VBA & Macro Problems

Use DateAdd and Select Case for Rent Reviews in Microsoft Access

Huda QurayshiHuda Qurayshi Nov 20, 2026 871 views

Question details

Replace a nested Access IIf control source with a maintainable calculation for six lease types.

Use DateAdd and Select Case for Rent Reviews in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
A form calculates current rent from a lease start date, lease type, original rent, and review percentage.
Observed behavior
Each lease type needs a review date calculated with a year offset from zero to five, followed by a one-day subtraction.
Before you start

Identify the form controls or fields for the lease type, start date, rent, and review percentage. The function below expects non-null values and treats a review percentage of 5 as 5%; enable database content if Access blocks VBA.

Solution 1Recommended

Replace the nested IIf expression with a VBA function

Use a public function and Select Case to map the six lease types to review dates and calculate the rent.

The function subtracts one day from the date produced by DateAdd. If that date is on or before today, it applies one rent increase; otherwise, it returns the original rent. An unrecognized lease type also returns the original rent.

1
Create a standard module

In Access, open the database and select Create > Module to open the VBA editor. Save the standard module with a name such as RentReviewModule.

2
Add the calculation function

Paste this code into the module: Public Function GetCurrentRent(LeaseTypeFrame As Long, LeaseStart As Date, Rent As Double, ReviewPct As Double) As Double Dim DateToCompare As Date Dim YearOffset As Long Select Case LeaseTypeFrame Case 1: YearOffset = 0 Case 2: YearOffset = 1 Case 3: YearOffset = 2 Case 4: YearOffset = 3 Case 5: YearOffset = 4 Case 6: YearOffset = 5 Case Else GetCurrentRent = Rent Exit Function End Select DateToCompare = DateAdd("yyyy", YearOffset, LeaseStart) - 1 If DateToCompare <= Date Then GetCurrentRent = Rent + Rent * ReviewPct / 100 Else GetCurrentRent = Rent End If End Function

3
Set the control source

Open the form in Design View, select the calculated control, and open its Property Sheet. On the Data tab, set Control Source to =GetCurrentRent([LeaseTypeFrame],[LeaseStart],[Rent],[ReviewPct]). Replace the names with the actual field or control names in your form.

4
Test the calculation

In the VBA editor, press Ctrl+G to open the Immediate window and enter ?GetCurrentRent(2, DateSerial(2017, 1, 1), 1234, 5). Also test dates before and on the calculated review date, plus an invalid lease type.

Replace the nested IIf expression with a VBA function
Check for missing values: The typed arguments do not accept Null. Ensure the referenced fields or controls contain valid values, or add explicit Null handling before calling the function.
Free Microsoft Office alternative

Work with rent review spreadsheets in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for working with spreadsheet documents. It can help you move spreadsheet-based rent records between office suites, but it does not replace Microsoft Access or run this Access form function.

Organize lease dates and rent review figures in WPS SpreadsheetsOpen and save Microsoft Excel XLSX files for sharingUse a familiar spreadsheet interface for an easier transitionWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

How are the six lease types mapped to review dates?

Lease types 1 through 6 use year offsets of 0 through 5 respectively. The function applies DateAdd to LeaseStart and then subtracts one day.

What happens if the review date is today?

The function applies the increase because its comparison is DateToCompare <= Date. It returns the original rent if the review date is still in the future.

What should I enter for a 5% review increase?

Enter 5 in the ReviewPct field or control. The function divides that value by 100 before calculating the increase.

Why might the control show an error instead of the rent?

Check that the function is public in a standard module, the Control Source uses the correct field or control names, and none of its arguments is Null. Also enable database content if Access has blocked VBA.

Does this function apply multiple annual increases?

No. It applies the specified percentage once when the calculated review date has been reached, regardless of how much time has passed.