Access VBA - Reference to Subform disappears after database has been open a while -


i have microsoft access 2013 database has form hidden subform. there text box search value , button click search. there subform on form hidden until search button clicked. once button clicked, subform becomes visible , displays results of search.

this process works fine normally. however, last night left database open form displayed in initial state subform hidden. entered search value , clicked search , "object not exist" error. traced vba code , fails on first line references subform: subform.form.recordsource = "(some sql text)"

i read on 1 forum access can lose reference hidden control after period of time. assume case here, since when reload form, works fine.

this database may stay open on user's computers overnight prevent problem if possible. i'm wondering if there way write code checks see if subform still referenced in memory, , if not, reconnect reference. not sure if possible in vba. like:

if not subform.isloaded     subform.reload end if  subform.form.recordsource = "(some sql text)" 

does exist in vba...or there different way go solving problem?

this odd , have never seen this. yet, happening you.

one crude approach handle error handling. when user clicks search button, add error handling closes, reopens form, applies search using openargs data in openform method. rough code memory, like:

sub cmdsearch_click()  dim ssql string ssql = "my sql string params"  on error goto subform_lost_err  subform.form.recordsource = ssql   exit sub  subform_lost_err:     docmd.close acform, me.name    docmd.openform "thecurrentformname", , , , , , ssql   end sub 

then, add onload event handle if openargs passed in

private sub form_load() if nz(me.openargs, "") <> ""     subform.form.recordsource = me.openargs     me.paramstextbox = "theparams" 'cosmetic looks right. end if end sub 

i try getting handle on form in different ways. have no clue why lose handle, try things this:

forms("myform").subform.form.recordsource = "the sql" me!subform.form.recordsource  = "the sql" screen.activeform.subform.form.recordsource = "the sql" 

etc.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -