Matching Button Labels with Open Form (1 Viewer)

Danick

Registered User.
Local time
Yesterday, 20:46
Joined
Sep 23, 2008
Messages
351
I am trying to have a "Ribbon" type switchboard form (frm0) that will stay open all the time until the user closes the database. This form has buttons (Actually Labels acting as buttons) to open other forms. I'm trying to get the buttons on the switchboard to change color to match the form that is currently active but I'm having a little trouble. I've attached a sample database to illustrate.

For instance, if the user clicks FORM 1, then clicks FORM 2, then all is fine. frm2 is displayed and FORM 2 button is shown in color. But if the user closes frm2, then the user will see frm1 again, but the corresponding FORM 1 button does not highlight until the user clicks that frm1 and brings it into focus.

Is there anyway to make the previous frm1 go back into focus without having to make the switchboard a popup form? Basically, I want the top most form (other than frm0) to automatically get focus.

Thanks
 

Attachments

  • BottonColorChanges.accdb
    464 KB · Views: 76
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:46
Joined
Oct 29, 2018
Messages
21,454
Hi. The only thing I could suggest is to use the form's Close event to send the focus to one of the open forms.
 

Danick

Registered User.
Local time
Yesterday, 20:46
Joined
Sep 23, 2008
Messages
351
Hi. The only thing I could suggest is to use the form's Close event to send the focus to one of the open forms.

There is no way to know which form was just below the form the user closed. Need to find a way to know which is the TOP MOST form being displayed to set focus on that form.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 17:46
Joined
Oct 29, 2018
Messages
21,454
There is no way to know which form was just below the form the user closed. Need to find a way to know which is the TOP MOST form being displayed to set focus on that form.
Hi. I can't tell if that's a statement or a question. There's probably a way to determine the order of open windows using API (although I have no idea which one to use). However, if there isn't any, then maybe you could add some code in the switchboard/ribbon form to keep track of the order in which the user clicked each button and then use it to determine which form to set the focus on. Just a thought...
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:46
Joined
May 21, 2018
Messages
8,525
I tried this to see how involved it would be.
1)You have to add it to the collection and remove previous additions every time you open the form.
2)You have to remove it from the collection when you close
3)If there is a form in the queue then hilight the last in the queue
switchboard code.
Code:
Option Compare Database

Public MyForms As New Collection
Private defaultColor  As Long

Private Sub cmdfrm1_Click()
 DoCmd.OpenForm "frm1", acNormal, "", "", , acNormal
 RestoreButtons
 Me.cmdfrm1.BackColor = RGB(204, 255, 255)
 AddForm "frm1"
End Sub
Private Sub cmdfrm2_Click()
  DoCmd.OpenForm "frm2", acNormal, "", "", , acNormal
  RestoreButtons
  Me.cmdfrm2.BackColor = RGB(204, 255, 255)
  AddForm "frm2"
End Sub
Private Sub cmdfrm3_Click()
  DoCmd.OpenForm "frm3", acNormal, "", "", , acNormal
  RestoreButtons
  Me.cmdfrm3.BackColor = RGB(204, 255, 255)
  AddForm "frm3"
End Sub
Public Sub HilightNext()
  Dim frmName As String
  If MyForms.Count > 0 Then
    frmName = MyForms(MyForms.Count)
    HilightButton frmName
  Else
    RestoreButtons
  End If
End Sub
Public Sub HilightButton(frmName)
   RestoreButtons
  MsgBox frmName
  Select Case frmName
    Case "frm1"
     Me.cmdfrm1.BackColor = RGB(204, 255, 255)
    Case "frm2"
     Me.cmdfrm2.BackColor = RGB(204, 255, 255)
    Case "frm3"
      Me.cmdfrm3.BackColor = RGB(204, 255, 255)
  End Select
End Sub
Public Sub RestoreButtons()
  Me.cmdfrm1.BackColor = defaultColor
  Me.cmdfrm2.BackColor = defaultColor
  Me.cmdfrm3.BackColor = defaultColor
End Sub
Public Sub AddForm(frmName As String)
  DeleteOccurence frmName
  MyForms.Add (frmName)
End Sub
Public Sub DeleteOccurence(frmName As String)
  Dim i As Integer
  For i = MyForms.Count To 1 Step -1
    If MyForms(i) = frmName Then MyForms.Remove (i)
  Next i
End Sub
Private Sub Form_Load()
  defaultColor = vbWhite
End Sub

Then get rid of the focus events in the forms.
Add
Code:
Private Sub Form_Close()
  Dim frm As Form_frm0
  Set frm = Forms("frm0")
  frm.DeleteOccurence Me.Name
  frm.HilightNext
End Sub

It works, but not sure the bang is worth the buck.
 

Danick

Registered User.
Local time
Yesterday, 20:46
Joined
Sep 23, 2008
Messages
351
Thanks MajP. I used your code and it does seem to work. But as you said, probably too much buck for the bang. Especially since this was just a small sample of what I'm trying to do in my database which has a lot more buttons with a lot more forms and users can enter into some of the top forms from within each form. For example, frm3 would have a button that would open frm1 to a specific record that was being displayed in frm3.

So maybe this is too much to do in order to make it a bit more polished. I just like the way Microsoft Word, Excel, etc, changes the font in the top menu to show which tab you are currently on.

Thanks for the effort. You got a lot further than I did. Appreciate it.
 

Danick

Registered User.
Local time
Yesterday, 20:46
Joined
Sep 23, 2008
Messages
351
As theDBGuy said there may be some API calls that can help find the z-order. Take a look here
https://www.access-programmers.co.uk/forums/showthread.php?t=269503

I looked into that thread, but it seems to be more geared toward Windows and not specifically to Access. And way too much work to adapt it for my purpose.

I've got my app working now by changing the on focus event to on activate and deactivate events. Seems to do what I want it do about 95% of the time. Except when a user closes the form - no label is illuminated. But I think that's OK because the correct menu button illuminates as soon as the user clicks anywhere in the form being displayed. So I think that is good enough for me. Plus this is really just to make the application look a little more polished and not needed for functionality.

Thanks again and HAVE A GREAT WEEKEND!!
 

Users who are viewing this thread

Top Bottom