Question: I have a function in my VBA code which sets a specific Date format for a textbox.

This is my code to verify the Date is in the correct format:

```
Function CheckDate(DateStg As String) As Boolean

If DateStg = "" Then
  ' Accept an empty value in case user has accidentally moved to a new row
  CheckDate = True
  lblMessage.Caption = ""
  Exit Function
End If

If IsDate(DateStg) Then
  CheckDate = True
  lblMessage.Caption = ""
Else
  CheckDate = False
  lblMessage.Caption = "Sorry I am unable to recognise " & DateStg & " as a date."
End If

End Function

```

In addition to checking if the date in the textbox is an actual date, I need to verify that the textbox date is not less than the current date minus 1 month, and. Also, I would like to verify that the date is not more than the current date plus 1 year.

So: 

* DateStg > Today - 1 month
* DateStg < Today + 1 year

Thanks for your help in advance.

Answer: 
You have a few functions you can use:

```
''Assume date is not good
DateOK=False
If IsDate(DateStg) Then
     If DateStg > dateAdd("m",-1,Date()) _
         And DateStg < dateAdd("m",12,Date()) Then
        ''Date is good
        DateOK=True
     End If
End if

```

For the most part, textboxes can be set to only accept dates and you can set validation rules to check the range, so code may not be necessary.
If you just want to check the date, you can use the DateAdd-function to get the dates to compare:

```
'Subtract a month from today and return it as a string
Format(DateAdd("m", -1, Now), "yyyy-mm-dd")

'Add a year to today and return it as a string
Format(DateAdd("yyyy", 1, Now), "yyyy-mm-dd")

```