Hi, im new to this forum, and as far as I know. this hasn't been posted.
What I am trying to create is a log in system, and in one of my forms I want to limit the date entered into a form.
For example a user cannot enter a date more than seven days from todays date
Which is what i achieved but what i am stuck on is
preventing a user entering a date in the future
Anyone who can help, I would be very greatful
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dateDifference As Integer ' this variable keeps the difference between the dates.
Dim todaydte As Date = Now() 'Current date'
' Checks if date is valid
If (IsDate(TxtBox1.Text)) Then
' Get the difference between the dates (in days)
dateDifference = DateDiff("d", TxtBox1.Text, todaydte)
' Date difference more than 7 days?
If (dateDifference > 7) Then
' if its then displays error message'
MessageBox.Show("Date is out of range", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
'and form closes'
Me.Close()
Else
'if the date is 7 days or less message box will say
MessageBox.Show("Continue", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
'next screen will show
'form hides
Form5.Show()
Me.Hide()
End If
Else
'if a date is not entered then this will display
MessageBox.Show("Please input a valid date", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If