LO 184.108.40.206-snap1, Ubuntu 18.04 with all updates.
I have a Base form that can be called to show from more than one place. Given that I haven’t (yet) found how to show the form modally (I know it can be done with a dialog but I found it very painful!) I came up with the idea of dumping the name of the calling form into a hidden textbox on the active form so I can easily return to the parent - steps are:
- load new form
- push name of currentform into
- hide current form
- make form named in txtDaddy visible
- unload current form
sub StudentClassOpenFromDashboard(oEvent as object) '### Disable "Show Details" button on Dashboard then open details form' '### Called from fm_Dashboard' Dim oForm as object Dim oNewForm as object Dim ctl as object '### Disable button, open class form then hide dashboard' ctl = oEvent.source.model oForm = ctl.parent oForm.getByName("btnCurrent").enabled = False oNewForm =openForm( "frm_StudentClass") oNewForm.Controls("txtDaddy").value = "frm_Dashboard" Application.forms("frm_Dashboard").visible = false end sub
And to return to the calling form…
sub DB_CloseForm(pEvent as object) Dim sName, sParent as string Dim oFrm as object '### closes form and shows calling form.' '### Calling form name is stored in hidden "txtDaddy" field on form we are closing.' oFrm = pEvent.source.model.parent select case oFrm.name case "frmMainStuds" sName = "frm_StudMain" case "frmMainStudClass" sName = "frm_StudentClass" case "NewClassForm" sName = "frm_StudentClassNew" end select '### Show parent form before closing to avoid having a blank screen whilst it works!' sParent = oFrm.getByName("txtDaddy").text Application.Forms(sParent).visible = true DoCmd.mclose(2,sName,0) end sub
This seems to work well. HOWEVER…
I was debugging something and needed to show the contents of txtDaddy so made it visible. Then, I noticed that when the ‘Cancel Changes’ button of the form is pressed, txtDaddy was cleared along with all the bound controls - even though I have bound it to a field in the underlying table. Making it hidden excludes it from the reset process.
This in itself is not a problem, as the textbox is not normally visible and then, it seems, the value is left intact.
My question is can this behaviour be relied upon for the future or is it an oversight? Should I take the precaution of dumping my textbox into a subform that will not be affected by the cancel updates process?
PS Please forgive the sloppy switching of code between basic & Access2Base, I’m still learning how this works!