Make a control "Dirty"

  • Thread starter Thread starter bw
  • Start date Start date
B

bw

I want to perform a BeforeUpdate check on a date containing a date.
The procedure is shown below, and works fine when I manually enter the date.

Private Sub CarDateOut_BeforeUpdate(Cancel As Integer)
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date"
Cancel = True
End If
End Sub

However, if I update the control using the following, the BeforeUpdate
procedure above does not get executed.
I have shown where I want to insert code to indicate that a change to the
control has been made.

Can someone provide the code to do this, OR, tell me whats wrong with what
I'm trying to do?

Private Sub CarOut_Click()
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
'Insert code here to make the "CarDateOut_BeforeUpdate" procedure exit.
End Sub

Thanks,
Bernie
 
Just call the BeforeUpdate procedure in your code:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
Call CarDateOut_BeforeUpdate(intTemp)
End Sub
 
Thanks for the reply, Ken.

When I enter the date manually (and it is less than TravelDate), the cursor
is flashing in a location immediately after the date. I must press the Esc
key to "Cancel" the wrong input and re-enter.

When I Call the procedure as you have suggested, the cursor highlights the
entire date, and the Esc key produces no action. In other words, I get the
message that there is an error, but I'm NOT forced to correct it.

Can you explain?

Thanks,
Bernie


Ken Snell (MVP) said:
Just call the BeforeUpdate procedure in your code:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
Call CarDateOut_BeforeUpdate(intTemp)
End Sub

--

Ken Snell
<MS ACCESS MVP>

bw said:
I want to perform a BeforeUpdate check on a date containing a date.
The procedure is shown below, and works fine when I manually enter the
date.

Private Sub CarDateOut_BeforeUpdate(Cancel As Integer)
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date"
Cancel = True
End If
End Sub

However, if I update the control using the following, the BeforeUpdate
procedure above does not get executed.
I have shown where I want to insert code to indicate that a change to the
control has been made.

Can someone provide the code to do this, OR, tell me whats wrong with
what I'm trying to do?

Private Sub CarOut_Click()
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
'Insert code here to make the "CarDateOut_BeforeUpdate" procedure exit.
End Sub

Thanks,
Bernie
 
What does the procedure "CalendarFor" do? Post its code.

--

Ken Snell
<MS ACCESS MVP>


bw said:
Thanks for the reply, Ken.

When I enter the date manually (and it is less than TravelDate), the
cursor is flashing in a location immediately after the date. I must press
the Esc key to "Cancel" the wrong input and re-enter.

When I Call the procedure as you have suggested, the cursor highlights the
entire date, and the Esc key produces no action. In other words, I get
the message that there is an error, but I'm NOT forced to correct it.

Can you explain?

Thanks,
Bernie


Ken Snell (MVP) said:
Just call the BeforeUpdate procedure in your code:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
Call CarDateOut_BeforeUpdate(intTemp)
End Sub

--

Ken Snell
<MS ACCESS MVP>

bw said:
I want to perform a BeforeUpdate check on a date containing a date.
The procedure is shown below, and works fine when I manually enter the
date.

Private Sub CarDateOut_BeforeUpdate(Cancel As Integer)
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date"
Cancel = True
End If
End Sub

However, if I update the control using the following, the BeforeUpdate
procedure above does not get executed.
I have shown where I want to insert code to indicate that a change to
the control has been made.

Can someone provide the code to do this, OR, tell me whats wrong with
what I'm trying to do?

Private Sub CarOut_Click()
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
'Insert code here to make the "CarDateOut_BeforeUpdate" procedure exit.
End Sub

Thanks,
Bernie
 
Per your request, the code for "CalendarFor" and related code:

'Author: Allen Browne. (e-mail address removed)
'You may use this example for private, business, or educational purposes,
with acknowledgement.
'However, you may not publish it without the express, written permission of
the author.

'You also need this code in a standard module:

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Let me know if you need more information.
Bernie

Ken Snell (MVP) said:
What does the procedure "CalendarFor" do? Post its code.

--

Ken Snell
<MS ACCESS MVP>


bw said:
Thanks for the reply, Ken.

When I enter the date manually (and it is less than TravelDate), the
cursor is flashing in a location immediately after the date. I must
press the Esc key to "Cancel" the wrong input and re-enter.

When I Call the procedure as you have suggested, the cursor highlights
the entire date, and the Esc key produces no action. In other words, I
get the message that there is an error, but I'm NOT forced to correct it.

Can you explain?

Thanks,
Bernie


Ken Snell (MVP) said:
Just call the BeforeUpdate procedure in your code:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
Call CarDateOut_BeforeUpdate(intTemp)
End Sub

--

Ken Snell
<MS ACCESS MVP>

I want to perform a BeforeUpdate check on a date containing a date.
The procedure is shown below, and works fine when I manually enter the
date.

Private Sub CarDateOut_BeforeUpdate(Cancel As Integer)
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date"
Cancel = True
End If
End Sub

However, if I update the control using the following, the BeforeUpdate
procedure above does not get executed.
I have shown where I want to insert code to indicate that a change to
the control has been made.

Can someone provide the code to do this, OR, tell me whats wrong with
what I'm trying to do?

Private Sub CarOut_Click()
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
'Insert code here to make the "CarDateOut_BeforeUpdate" procedure exit.
End Sub

Thanks,
Bernie
 
Am I correct that the CalendarFor process is writing the date into the
CarDateOut control? Do you get the message box from the BeforeUpdate event
procedure with the code that I suggested? Or do you get no message at all,
just the "flashing cursor"?

Using the BeforeUpdate event to validate a value entered by another
procedure is not the way I would run your setup. Instead, why not just do
the validation in the button's code that calls the Calendar form? So this is
what I'd use:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date")
CarDateOut = Null
End If
End Sub

--

Ken Snell
<MS ACCESS MVP>



bw said:
Per your request, the code for "CalendarFor" and related code:

'Author: Allen Browne. (e-mail address removed)
'You may use this example for private, business, or educational purposes,
with acknowledgement.
'However, you may not publish it without the express, written permission
of the author.

'You also need this code in a standard module:

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Let me know if you need more information.
Bernie

Ken Snell (MVP) said:
What does the procedure "CalendarFor" do? Post its code.

--

Ken Snell
<MS ACCESS MVP>


bw said:
Thanks for the reply, Ken.

When I enter the date manually (and it is less than TravelDate), the
cursor is flashing in a location immediately after the date. I must
press the Esc key to "Cancel" the wrong input and re-enter.

When I Call the procedure as you have suggested, the cursor highlights
the entire date, and the Esc key produces no action. In other words, I
get the message that there is an error, but I'm NOT forced to correct
it.

Can you explain?

Thanks,
Bernie


Just call the BeforeUpdate procedure in your code:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
Call CarDateOut_BeforeUpdate(intTemp)
End Sub

--

Ken Snell
<MS ACCESS MVP>

I want to perform a BeforeUpdate check on a date containing a date.
The procedure is shown below, and works fine when I manually enter the
date.

Private Sub CarDateOut_BeforeUpdate(Cancel As Integer)
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date"
Cancel = True
End If
End Sub

However, if I update the control using the following, the BeforeUpdate
procedure above does not get executed.
I have shown where I want to insert code to indicate that a change to
the control has been made.

Can someone provide the code to do this, OR, tell me whats wrong with
what I'm trying to do?

Private Sub CarOut_Click()
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
'Insert code here to make the "CarDateOut_BeforeUpdate" procedure
exit.
End Sub

Thanks,
Bernie
 
Thank you so much Ken!

Your new solution works even better than the original manual method.
I really appreciate your help and staying with me on this.
Thanks again,
Bernie


Ken Snell (MVP) said:
Am I correct that the CalendarFor process is writing the date into the
CarDateOut control? Do you get the message box from the BeforeUpdate event
procedure with the code that I suggested? Or do you get no message at all,
just the "flashing cursor"?

Using the BeforeUpdate event to validate a value entered by another
procedure is not the way I would run your setup. Instead, why not just do
the validation in the button's code that calls the Calendar form? So this
is what I'd use:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date")
CarDateOut = Null
End If
End Sub

--

Ken Snell
<MS ACCESS MVP>



bw said:
Per your request, the code for "CalendarFor" and related code:

'Author: Allen Browne. (e-mail address removed)
'You may use this example for private, business, or educational purposes,
with acknowledgement.
'However, you may not publish it without the express, written permission
of the author.

'You also need this code in a standard module:

Public Function CalendarFor(txt As TextBox, Optional strTitle As String)
On Error GoTo Err_Handler
'Purpose: Open the calendar form, identifying the text box to return
the date to.
'Arguments: txt = the text box to return the date to.
' strTitle = the caption for the calendar form (passed in
OpenArgs).

Set gtxtCalTarget = txt
DoCmd.OpenForm "frmCalendar", windowmode:=acDialog, OpenArgs:=strTitle

Exit_Handler:
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation,
"CalendarFor()"
Resume Exit_Handler
End Function

Let me know if you need more information.
Bernie

Ken Snell (MVP) said:
What does the procedure "CalendarFor" do? Post its code.

--

Ken Snell
<MS ACCESS MVP>


Thanks for the reply, Ken.

When I enter the date manually (and it is less than TravelDate), the
cursor is flashing in a location immediately after the date. I must
press the Esc key to "Cancel" the wrong input and re-enter.

When I Call the procedure as you have suggested, the cursor highlights
the entire date, and the Esc key produces no action. In other words, I
get the message that there is an error, but I'm NOT forced to correct
it.

Can you explain?

Thanks,
Bernie


Just call the BeforeUpdate procedure in your code:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
Call CarDateOut_BeforeUpdate(intTemp)
End Sub

--

Ken Snell
<MS ACCESS MVP>

I want to perform a BeforeUpdate check on a date containing a date.
The procedure is shown below, and works fine when I manually enter
the date.

Private Sub CarDateOut_BeforeUpdate(Cancel As Integer)
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date"
Cancel = True
End If
End Sub

However, if I update the control using the following, the
BeforeUpdate procedure above does not get executed.
I have shown where I want to insert code to indicate that a change to
the control has been made.

Can someone provide the code to do this, OR, tell me whats wrong with
what I'm trying to do?

Private Sub CarOut_Click()
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
'Insert code here to make the "CarDateOut_BeforeUpdate" procedure
exit.
End Sub

Thanks,
Bernie
 
You're welcome.

bw said:
Thank you so much Ken!

Your new solution works even better than the original manual method.
I really appreciate your help and staying with me on this.
Thanks again,
Bernie


Ken Snell (MVP) said:
Am I correct that the CalendarFor process is writing the date into the
CarDateOut control? Do you get the message box from the BeforeUpdate
event procedure with the code that I suggested? Or do you get no message
at all, just the "flashing cursor"?

Using the BeforeUpdate event to validate a value entered by another
procedure is not the way I would run your setup. Instead, why not just do
the validation in the button's code that calls the Calendar form? So this
is what I'd use:

Private Sub CarOut_Click()
Dim intTemp As Integer
On Error GoTo Err_CarOut_Click
WhichCalendar = 3
Call CalendarFor([CarDateOut], "Date Out")
If CarDateOut < Forms!Maketravelrequest!TravelDate Then
MsgBox "Car DateOut must be >= Travel Date")
CarDateOut = Null
End If
End Sub


< snipped >
 
Back
Top