Action on one form to cause action on another

S

Stockwell43

Hello,

I have a main form for inputting data and there is a checkbox for Complete
that when clicked will display the current date and this works fine. Here is
the code I put in the click event of the checkbox:
Private Sub Completed_Click()
Dim intValue As Integer
intValue = Completed.Value

Select Case intValue
Case 0
DateCompleted = Null
Case Else
DateCompleted = FormatDateTime(Now(), vbShortDate)
End Select

End Sub

I have another form that displays ONLY shows the task that are overdue which
is updated from a query(main form is from a table). When I open the overdue
form and click on the completed checkbox, it shows it checked on the main
form for that task but the current date in the Date completed field is still
blank. How do I get the date field to fill in when I click the checkbox from
the other form, do I somehow have to reference the form name?

Thanks!!
 
K

Ken Sheridan

The second form will only show the updated DateCompleted value once the main
form's record is saved. Add the following line to your code:

Me.Dirty = False

A few other points:

1. Its better to use the AfterUpdate event procedure rather than the Click
event procedure in a case like this. It won't make any difference in this
instance, but you could have a situation where an update fails for some
reason (key or index violation for instance) in which case the Click event
procedure would still execute, but not the AfterUpdate event procedure.

2. You are relying on the implementation of Boolean values as 0 or -1.
Reliance on the implementation is not good programming practice (its being
"unduly chummy with the implementation" to quote the head of one software
company of my acquaintance). Use the Boolean FALSE and TRUE constants
instead.

3. You can simply assign the return value of the Date function rather than
formatting the return value of the Now function.

4. You don't need to specify the Value property as it’s the default
property of the control.

So:

Dim blnValue As Boolean

blnValue = Me.Completed

Select Case blnValue
Case False
DateCompleted = Null
Case Else
DateCompleted = VBA.Date
End Select

Me.Dirty = False

Ken Sheridan
Stafford, England
 
S

Stockwell43

Hi Ken, thank you for responding.

I did place the code in the After Update and it works great, thanks!!!

I am not very good with code, as I am still learning but gaining ground
(slowly) :blush:)

I was trying to come up something that if the user didn't mean to check the
box they could uncheck it and the date would disappear as well. It worked but
feel more comfortable with yours now know why. Thank you for explaining and I
copied the information and am saving it in my folder with the rest of my code
snippets and information.

Thank you again and have a great weekend!!
 

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

Similar Threads


Top