I have a Microsoft Access 2013 database that has a form with a hidden subform. There is a text box for a search value and a button to click to search. There is a subform on the form that is hidden until the search button is clicked. Once that button is clicked, the subform becomes visible and displays the results of the search.
This process works fine normally. However, last night I left the database open with the form displayed in its initial state with the subform hidden. I entered a search value and clicked search and I get an "object does not exist" error. I traced the VBA code and it fails on the first line that references the subform: SubForm.Form.RecordSource = "(some sql text)"
I read on one forum that Access can lose the reference to a hidden control after a period of time. I assume that is the case here, since when I reload the form, it works fine.
This is a database that may stay open on user's computers overnight so I would like to prevent this problem if possible. I'm wondering if there is a way to write some code that checks to see if the subform is still referenced in memory, and if it is not, reconnect the reference. Not sure if this is even possible in VBA. Something like:
If Not SubForm.IsLoaded Then
SubForm.Reload
End If
SubForm.Form.RecordSource = "(some sql text)"
Does anything like this exist in VBA...or is there a different way to go about solving this problem?