To not allow entry of duplicate dates

G

Guest

I have a form which displays as well as a lot of other fields, two important
ones, [startdate] & [enddate], I would like a simple message box to pop up
informing the user that they have input an incorrect enddate (the startdate
should never match the enddate).

Then after the message box has been closed by the user, the enddate they
input is cleared and the cursor is ready for them to try again.

If it is possible to provide me with the code, that would be extremely useful.

thanks in advance
 
G

Guest

Put this in the enddate "before update" event and see what happens:

if enddate = startdate then msgbox "You have entered a wrong end date.
Please try again", vbcritical
enddate = null
 
G

Guest

Thank you scubadiver, I'll give this a go.

Could I ask another question, say I wanted the enddate to not be less than 4
days from the startdate, what code would you use then?

thanks again

scubadiver said:
Put this in the enddate "before update" event and see what happens:

if enddate = startdate then msgbox "You have entered a wrong end date.
Please try again", vbcritical
enddate = null

--

http://www.ready4mainstream.ny911truth.org/index.html


Mr-Re Man said:
I have a form which displays as well as a lot of other fields, two important
ones, [startdate] & [enddate], I would like a simple message box to pop up
informing the user that they have input an incorrect enddate (the startdate
should never match the enddate).

Then after the message box has been closed by the user, the enddate they
input is cleared and the cursor is ready for them to try again.

If it is possible to provide me with the code, that would be extremely useful.

thanks in advance
 
G

Guest

I thought it would work but it hasn't. The message comes up even if the
dates are different.

--

http://www.ready4mainstream.ny911truth.org/index.html


Mr-Re Man said:
Thank you scubadiver, I'll give this a go.

Could I ask another question, say I wanted the enddate to not be less than 4
days from the startdate, what code would you use then?

thanks again

scubadiver said:
Put this in the enddate "before update" event and see what happens:

if enddate = startdate then msgbox "You have entered a wrong end date.
Please try again", vbcritical
enddate = null

--

http://www.ready4mainstream.ny911truth.org/index.html


Mr-Re Man said:
I have a form which displays as well as a lot of other fields, two important
ones, [startdate] & [enddate], I would like a simple message box to pop up
informing the user that they have input an incorrect enddate (the startdate
should never match the enddate).

Then after the message box has been closed by the user, the enddate they
input is cleared and the cursor is ready for them to try again.

If it is possible to provide me with the code, that would be extremely useful.

thanks in advance
 
G

Guest

It has turned out to be a lot more difficult than I thought it would be.

having said that it might be easier for the two dates to be combo boxes and
set the "end date" to be later than the start date

create a query for the "enddate" and put the following in the criteria box.
[forms]![reports form]![startdate]

Insert the following into the afterupdate event of "startdate"

enddate.requery

If it has to be at least four days then that can be included in the criteria
as well.

Otherwise I am struggling.

--

http://www.ready4mainstream.ny911truth.org/index.html


Mr-Re Man said:
Thank you scubadiver, I'll give this a go.

Could I ask another question, say I wanted the enddate to not be less than 4
days from the startdate, what code would you use then?

thanks again

scubadiver said:
Put this in the enddate "before update" event and see what happens:

if enddate = startdate then msgbox "You have entered a wrong end date.
Please try again", vbcritical
enddate = null

--

http://www.ready4mainstream.ny911truth.org/index.html


Mr-Re Man said:
I have a form which displays as well as a lot of other fields, two important
ones, [startdate] & [enddate], I would like a simple message box to pop up
informing the user that they have input an incorrect enddate (the startdate
should never match the enddate).

Then after the message box has been closed by the user, the enddate they
input is cleared and the cursor is ready for them to try again.

If it is possible to provide me with the code, that would be extremely useful.

thanks in advance
 
G

Guest

Use the Before Update event of the form, not the control. When you have two
or more controls to test against each other, the form Before Update is easier.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
Dim strCtl As String

With Me
If IsNull(.txtStartDate) Then
strMsg = "No Start Date Entered"
strCtl = "txtStartDStartDate"
ElseIf IsNull(.txtEndDate) Then
strMsg = "No End Date Entered"
strCtl = "txtEndDAte"
ElseIf DateDiff("d", .StartDate, .EndDate) < 4 Then
strMsg = "Earliest End Date is " & DateAdd("d",4, .txtStartDate)
strCtl = "txtEndDate"
End If
If Len(strMsg) > 0 Then
Cancel = True
MsgBox strMsg
Me.Controls(strCtl).SetFocus
End If
End With
End Sub
--
Dave Hargis, Microsoft Access MVP


Mr-Re Man said:
Thank you scubadiver, I'll give this a go.

Could I ask another question, say I wanted the enddate to not be less than 4
days from the startdate, what code would you use then?

thanks again

scubadiver said:
Put this in the enddate "before update" event and see what happens:

if enddate = startdate then msgbox "You have entered a wrong end date.
Please try again", vbcritical
enddate = null

--

http://www.ready4mainstream.ny911truth.org/index.html


Mr-Re Man said:
I have a form which displays as well as a lot of other fields, two important
ones, [startdate] & [enddate], I would like a simple message box to pop up
informing the user that they have input an incorrect enddate (the startdate
should never match the enddate).

Then after the message box has been closed by the user, the enddate they
input is cleared and the cursor is ready for them to try again.

If it is possible to provide me with the code, that would be extremely useful.

thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top