[SOLVED] Date comparison
What is wrong with the code below, it keep having "Run-time error '2185': You can't reference a property or method for a control unless the control has the focus."
I just want to calculate the difference of the days with the input txtStartDate.Text & txtEndDate.Text on the form & fill another textbox, txtDaysLeave.Text, with the days difference.
The error happens on the line when I compare the start date(txtStartDate.Text) & end date(txtEndDate.Text).
-> Both are textboxes (however they come with date picker tool when clicked)
These textbox corresponds to date field of my table, Leave_Details.
What is wrong with the code below, it keep having "Run-time error '2185': You can't reference a property or method for a control unless the control has the focus."
I just want to calculate the difference of the days with the input txtStartDate.Text & txtEndDate.Text on the form & fill another textbox, txtDaysLeave.Text, with the days difference.
Code:
Private Sub txtEndDate_Change()
Dim intDays As Integer
intDays = DateDiff("d", txtStartDate.Text, txtEndDate.Text)
txtDaysLeave.Text = CStr(intDays)
End Sub
The error happens on the line when I compare the start date(txtStartDate.Text) & end date(txtEndDate.Text).
-> Both are textboxes (however they come with date picker tool when clicked)
These textbox corresponds to date field of my table, Leave_Details.
Last edited: