Hi there

recently I received help on how to ensure that a user don't close a form before he/she completes all outstanding entries on a calendar.

That works perfectly, but now the problem is I have to complete all entries up to say the year 2020. I only want the handler to check entries from january 2010 up to the cureent day. Ho can I do that?

The code I have is my time mangement module and looks like this......

Public Sub CloseMyApplication(frm As Form)

Dim MyLabel As Control

For Each MyLabel In frm.Controls
If TypeOf MyLabel Is Label Then
If MyLabel.ForeColor = vbRed Then
MsgBox "Please complete all outstanding entries", , "Message"
Cancel = True
Else
End If

If MyLabel.ForeColor = vbWhite Then
JobBook.Show
TimeManage.Hide
End If
End If

Next MyLabel
End Sub

I only want the handler to check entries from january 2010 up to the cureent day. Ho can I do that?

Firstly, what entries are we talking about?
Will these entries be open or closed?

Well these entries will be clicked on and display all jobs that are done for the day. So basically they wont be opened. The will instead just be viewed.

I'm still confused.

Bookings/Entries will be made in advance to say the year 2020?
a User can however not check an entry if it is after today, because no jobs has been completed as yet?

The user can only view a completed job up till today, IF IT WAS CLOSED by clicking on a certain date in the list?

Okay let me explain it this way..

Forget about what lies on each calendar entry. All I would like to know is how can I ensure how the user must complete all jobs from January 2010 up to the current date. The code I use above works perfectly but it counts up to wherever, somewhere in a few months time, don't know. When I close the form with the above code it see's lets say tomorrows as incomplete.

Ok, now I understand. You want it to read the color of the labels, but only up to todays date, where today is every new day?

Any future bookings must be ignored.

that's correct yes. :)

no, each label starts with '0 / 8.5' where the 0 updates every time a job is added for the day. at the end of each day the label should be '8.5 / 8.5'. If not then that handler I'm looking for should kick in :)

Then quite easy -

Public Sub CloseMyApplication(frm As Form)
 
Dim MyLabel As Control
 
For Each MyLabel In frm.Controls
If TypeOf MyLabel Is Label Then
'JUST ADD THE CAPTION TO READ 0/8.5...
If MyLabel.ForeColor = vbRed And Not MyLabel.Caption = "0/8.5" Then
MsgBox "Please complete all outstanding entries", , "Message"
Cancel = True
Else
End If
 
If MyLabel.ForeColor = vbWhite Then
JobBook.Show
TimeManage.Hide
End If
End If
 
Next MyLabel
End Sub

That works :) yay!! but now when i close the form and the label is red it closes and then only gives me the messagebox. Where did i go wrong?

in my form i call the the method in the module like this:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If UnloadMode = vbFormControlMenu Then

Call CloseMyApplication(Me)

End If
End Sub

I'm figuring the problem might be here??

Don't call the "CloseMyApp" in the unload event of your form. It will unload the form, run the function, hence the message box after closing.

This article has been dead for over six months. Start a new discussion instead.