Give us some more info on your named instances. What is TMData, TMcnt etc.
What code do you have under refresh_tmdata?
What calender control is Calender1?
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Does this part here below change the label fore color to white if a task has been completed, or it stays red if a task is still outstanding?
If etime < 8.5 Then
Tlabel.ForeColor = vbRed
Else
Tlabel.ForeColor = vbWhite
End If
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
In other words, if a calender entry is still outstanding, the label will be red?
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Cool, then your problem is very easily resolved.
In a module add the following code...
Option Explicit
Public Sub CloseMyApplication(frm As Form)
Dim Control As Control
For Each Control In frm.Controls
If TypeOf Control Is Label Then
If Label.ForeColour = vbRed Then
'Code here NOT to close the app
Else
'All entries or tasks is completed, close the application
End If
End If
Next Control
End Sub
'In your form the following...
Call CloseMyApplication (Me)
Let me know if this helps.:)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
My bad!!! I mixed up the code a bit. You have declared Control as the handler. We then used label to put the call to it, shame on me:)
Paste the following in your module -
In a module add the following code...
Option Explicit
Public Sub CloseMyApplication(frm As Form)
Dim MyLabel As Control
For Each Control In frm.Controls
If TypeOf Control Is Label Then
If MyLabel.ForeColour = vbRed Then
'Code here NOT to close the app
Else
'All entries or tasks is completed, close the application
End If
End If
Next Control
End Sub
'In your form the following...
Call CloseMyApplication (Me)
Or, to use yours, the following -
Public Sub CloseMyApplication(frm As Form)
Dim MyLabel As Control
For Each Control In TimeManage.Controls
If TypeOf Control Is Label Then
If MyLabel.ForeColor = vbRed Then
MsgBox "Please complete all outstanding entries", , "Message"
Cancel = True
Else
If MyLabel.ForeColor = vbWhite Then
JobBook.Show
TimeManage.Hide
End If
End If
End If
Next Control
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
No, that reference all the labels in your Form. It will only effect the labels with a white or red backcolour though.
What error do you get and on which line?
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Use the code exactly as it is here. It works fine. Do NOT change your form name, label names etc.:)
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
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
It was a pleasure. Please mark this thread as solved and open a new thread with your calender question. We'll take it from there then. The reason being to keep questions and their solutions together, thanks.:)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350