Help with default value for textbox

Pikeboy

Registered User.
Local time
Yesterday, 21:17
Joined
May 24, 2012
Messages
11
I've got a form that performs some vba on load. It does a datediff to see if the current date is less than 1 when compared to the current value of a textbox. If this value is indeed less than one, it asks the user via an input box when the next pay day is. However, upon doing so it populates the textbox with 12/30/1899? The property of the textbox is set to short date. What gives? Code is below and thanks in advance.

Dim daysRemaining As Single
Dim payDate As Date
Dim rs As Date

On Error Resume Next

payDate = Me.txtNextPayDay

daysRemaining = (DateDiff("n", Date$, payDate)) / 1440

If daysRemaining < 1 Then
rs = InputBox("Enter next pay date:")
Me.txtNextPayDay.DefaultValue = Format(rs, "Short Date")
End If
 
I believe that the problem is because the date field has a NULL Value or the syntax does not match up.. Check two things..

1. The field has some date to perform DateDiff.. As null value will return default 31/12/1899.. Try to catch Null values using Nz..

2. Make sure that the Format is MM-DD-YYYY in the Date field you are using.. AS the Date$ will return 10-01-2012(the above mentioned format) whereas Date will return 01/10/2012(DD/MM/YYYY)..
 
Here is what I ended up getting to work (I changed daysremaining check to '0' as less than 1 but greater than 0 meant pay day still hadn't come yet :o(

If daysRemaining < 0 Then
rs = InputBox("Please enter next pay date:")
rs = "#" & rs & "#"
Me.txtNextPayDay = rs
End If

The "#" did the trick as rs had been declared as a date.........
 

Users who are viewing this thread

Back
Top Bottom