Check if is a date error - VBA

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
Hi all, I am getting Run-time error '5': invalid procedure call or argument on the first line of this code...

I have a form that is has txt field where the user inserts the date and time to be processed, by default the value is returned by now().

For example the value in the text box (txtStartDate) is 8/23/2011 11:15:19 AM

Code:
If (Not IsDate(Me.txtStartDate)) Or (Me.txtStartDate > DateAdd(w, 1, Now())) Then
    MsgBox "Start Date NOT VALID DATE, Please Try Again"
    writeToLog "[RunBatchLoad] ERROR " & Now()
    writeToLog "#RBL# * START DATE ERROR *"
    writeToLog "#RBL# * User: " & strUser
    writeToLog "#RBL# * Source: " & cmbSource
    writeToLog "#RBL# * Catergory: " & cmbCatergory
    writeToLog "#RBL# * Activity: " & cmbActivity
    writeToLog "#RBL# * Quantity: " & txtQuantity
    writeToLog "#RBL# * Start Date/Time: " & txtStartDate
    writeToLog "#RBL# * Interval: " & txtIntervalTime & " " & cmbIntervalPeriod
    writeToLog "*****************************"
    Valid = False
    GoTo End_Sub
End If
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe ...

Code:
    Dim bBad As Boolean
    Dim myDate As Date
    
    bBad = Not IsDate(Me.txtStartDate)
    If Not bBad Then
        myDate = CDate(Me.txtStartDate)
        bBad = myDate > Now() + 1
    End If
    
    If bBad Then
        '...
    End If
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top