Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Got Focus not working? 1

Status
Not open for further replies.

Chummly66

MIS
Feb 19, 2005
106
US
Hey there...

I have a form which I use for a switch board. The form as a button which when selected, opens a new form that is called frmToDoListing. This form has a list box which displays all my open todo items, based on a query. From this form, I can then select one of the todo items or select a New button which opens another form, frmtoDoEntry, which I can then mark a todo item completed, or make a new one. When I close the frmtoDoEntry, it returns to the previous form, frmToDoListing, and it refreshes to remove any newly closed todo items, or will show the newly added todo items. I close this form, and then I am back to the SwitchBoard form. While this all happens, the SwitchBoard form is in the background; its not closed.

I have this code which redoes the font on the toDo button on the switchboard form, which tells me there are open todo items and should be looked at. When there are no open todo items, the button is displayed with a normal font, letting me knownothing needs to be looked at. here is the code:

Private Sub Form_GotFocus()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim db1 As DAO.Database
Dim rs1 As DAO.Recordset
Dim strSql1 As String

Set db = CurrentDb
strSql = "Select Count(*) As OpenRecs from tblToDo Where IsNull(txtDateCompleted)"
Set rs = db.OpenRecordset(strSql)
If rs!Openrecs > 0 Then
Me.btnToDoListing.ForeColor = vbRed
Me.btnToDoListing.FontSize = 14
Else
Me.btnToDoListing.ForeColor = vbBlue
Me.btnToDoListing.FontSize = 8
End If
End Sub

The code works fine as long as you close and reopen the switchboard form. However, this code will not work when I close the frmToDoListing form, which places the switchboard form as the only form open, and thus placing the focus back on it.

Am I doing this wrong, or am I not understanding what the GotFocus optin is suppose to be used for? Is the only option to close and reopen the switchboard form?

thanks in advance!
Richard
 
Here's a thought. Why not make a separate subroutine, perhaps called Sub IndicateNewToDos and call it from the LostFocus events of the various places where a change can be made?

If it is placed in the form, you can continue to use "Me" otherwise, you'd have to change the code to identify the form where the button is located.

I hope this helps.
 
Alan,

Thank you so much. I never thought of doing it that way, but it worked like a charm. thanks for the reply!!

Richard
 
No problem. From time-to-time, everyone gets stuck in a way of thinking.

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top