Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:34:47+00:00 2026-06-09T19:34:47+00:00

I have a function in my VBA code which sets a specific Date format

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:34:49+00:00Added an answer on June 9, 2026 at 7:34 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this formula in a cell: =GetData(Channel_01,Chicago) Which executes this code: Public Function
I have this piece of code that originally uses the replace function(VBA) to replace
I have an EXCEL VBA function which should return the address of the first
I have a UDF non-volatile function in VBA, which requires a global variable (callback
I have some VBA code that opens a webpage, then calls a javascript function
I have a problem with calling the Match function from a VBA code: it
In my project I have some code which has been deveoped in VBA and
I have the following code in VBA (which resides in an Excel 2007 Workbook):
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function some_func_1 which will create an object of type some_type and will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.