Inconsistent Tab Focuses/Views with OpenForm??? (1 Viewer)


Mar 30, 2022

I apologize that I may not be using the right terminology here, but this is my situation. For some controls, DoCmd.OpenForm will open the requested form and immediately switch the view to the tab containing the form. On other controls, the view will remain on the display form. I can't figure out why. My DB display form has these controls:

The Add New Item / Edit Item / Add New Person / Edit Person controls operate as intended. This is the code that operates them (using Add New Item button as example):
Private Sub CmdOpenAddNewItem_Click()

DoCmd.OpenForm "AddNewItem", acNormal, , , acFormAdd, acWindowNormal

End Sub

The problem is when I open forms from other windows. If the user searches for an item or person in either of the two search boxes, AfterUpdate brings up a a pop-up form ([frmSearchSelectItem] and [frmSearchSelectPerson]) that displays all the matches for their search. Each match is a hyperlink that uses this code
PrivateSub ItemName_Click()

DoCmd.OpenForm "frmViewItem", acNormal, "", "[ItemID]=[Forms]![frmSearchSelectItem]![ItemID]", acFormReadOnly, acWindowNormal

DoCmd.Close acForm, "frmSearchSelectItem"

End Sub

The code opens the desired form, but when the popup form closes, the view defaults back to the display form, and the user has to click the appropriate tab to access the form that just opened. I have tried removing the DoCmd.Close line from the code, and interestingly, the opened form is visible behind the popup, but as soon as I close the popup (either with the X button or the cancel button I put on the popup), the view switches back to the display form. Is there a way to get the just-opened form to remain in view when the popup closes?

I'm designing this to be as easy to use as possible; the employees that will eventually use this database have no experience whatsoever with this kind of software, and I won't be working here anymore to help them.
@pbaldy you did it!

The weird thing is, in one of my earlier attempts, I tried to set focus to a control on the new form, but the view kept going back to the display form. This time I just added Forms!frmViewItem.SetFocus to the Click() event and it worked like a charm. I can't believe it was something so simple.
No problemo! I think you can set focus to a control, but you have to set focus to the form first.

Users who are viewing this thread

Top Bottom