Prevent incorrect date entry (1 Viewer)

Groundrush

Registered User.
Local time
Today, 14:23
Joined
Apr 14, 2002
Messages
1,376
Hi All,

I'm trying to prevent users from entering dates prior to the 16-03-09 & any dates in the future

I created this code to prevent users from entering future dates & put it in the before update of the date field

Code:
If Me.txtTMDate >= Date Then
   MsgBox "This date is in the future, please check your records & try again"
   Me.txtTMDate = ""
   End If

I cant work out how to prevent users from entering dates prior to the 16/03/2009

I'm sure there is a better way of doing this

Any suggestions

Any help would be much appreciated

Thanks
 

Kryst51

Singin' in the Hou. Rain
Local time
Today, 08:23
Joined
Jun 29, 2009
Messages
1,898
Hi All,

I'm trying to prevent users from entering dates prior to the 16-03-09 & any dates in the future

I created this code to prevent users from entering future dates & put it in the before update of the date field

Code:
If Me.txtTMDate >= Date Then
   MsgBox "This date is in the future, please check your records & try again"
   Me.txtTMDate = ""
   End If

I cant work out how to prevent users from entering dates prior to the 16/03/2009

I'm sure there is a better way of doing this

Any suggestions

Any help would be much appreciated

Thanks

Have you tried your code with <= #16/03/09#
 

Groundrush

Registered User.
Local time
Today, 14:23
Joined
Apr 14, 2002
Messages
1,376
Have you tried your code with <= #16/03/09#

I did but after reading your post I see my mistake now

I forgot to use the # sign :eek:



Thanks :D
 

Steve R.

Retired
Local time
Today, 09:23
Joined
Jul 5, 2006
Messages
4,674
The code below prevents users from entering a dated earlier than January 9, 2007 (the date the database was created) or after the current date. This code is executed on the EXIT event. It seems that it should be executed on the BEFORE UPDATE event, but I had some issues with the BEFORE UPDATE event that I no longer recall.

Code:
Private Sub Text13_Exit(Cancel As Integer)
    Dim NotOutofBounds As Boolean
    NotOutofBounds = True
    If IsDate(Me.ActiveControl) Then
            If Me.Text13 < #1/9/2007# Then NotOutofBounds = False
            If Me.Text13 > Now() Then NotOutofBounds = False
        Else
            NotOutofBounds = True
            intResponse = 0
        End If

    If Not NotOutofBounds Then
            Call DateErrorMessage(intResponse)
            If intResponse = 1 Then DoCmd.CancelEvent
            If intResponse = 2 Then Me.Text13 = Null: Me.Text13.BorderColor = Me.Detail.BackColor
        Else
            Me.Text13.BorderColor = Me.Detail.BackColor
        End If
End Sub

Code:
Private Sub DateErrorMessage(intResponse)
    TITLE = "                     *** DATE ERROR ***"
    MSG1 = "Please enter a date between January 9, 2007 and " & Format(Now(), "short date")
    intResponse = MsgBox(MSG1, vbOKCancel, TITLE)
End Sub
 

Groundrush

Registered User.
Local time
Today, 14:23
Joined
Apr 14, 2002
Messages
1,376
The code below prevents users from entering a dated earlier than January 9, 2007 (the date the database was created) or after the current date. This code is executed on the EXIT event. It seems that it should be executed on the BEFORE UPDATE event, but I had some issues with the BEFORE UPDATE event that I no longer recall.

Code:
Private Sub Text13_Exit(Cancel As Integer)
    Dim NotOutofBounds As Boolean
    NotOutofBounds = True
    If IsDate(Me.ActiveControl) Then
            If Me.Text13 < #1/9/2007# Then NotOutofBounds = False
            If Me.Text13 > Now() Then NotOutofBounds = False
        Else
            NotOutofBounds = True
            intResponse = 0
        End If

    If Not NotOutofBounds Then
            Call DateErrorMessage(intResponse)
            If intResponse = 1 Then DoCmd.CancelEvent
            If intResponse = 2 Then Me.Text13 = Null: Me.Text13.BorderColor = Me.Detail.BackColor
        Else
            Me.Text13.BorderColor = Me.Detail.BackColor
        End If
End Sub

Code:
Private Sub DateErrorMessage(intResponse)
    TITLE = "                     *** DATE ERROR ***"
    MSG1 = "Please enter a date between January 9, 2007 and " & Format(Now(), "short date")
    intResponse = MsgBox(MSG1, vbOKCancel, TITLE)
End Sub

Intersting, I will have a look into that

cheers :)
 

Groundrush

Registered User.
Local time
Today, 14:23
Joined
Apr 14, 2002
Messages
1,376
Code:
Private Sub DateErrorMessage(intResponse)
    TITLE = "                     *** DATE ERROR ***"
    MSG1 = "Please enter a date between January 9, 2007 and " & Format(Now(), "short date")
    intResponse = MsgBox(MSG1, vbOKCancel, TITLE)
End Sub

Steve,

where does the second bit of code go? I saved it as a module but I'm getting errors.

Thanks
 

Users who are viewing this thread

Top Bottom