Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing a form using the form name which is storred in a textbox on another form 1

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
584
GB
Hello,

I have a form (frm_Log_Add_or_Edit) with an unbound textbox called: txt_form_to_refresh

This textbox receives the name of a form when it is opened.

When I close the form I want the vba to refresh the form whos name is stored in the unbound textbox: txt_form_to_refresh

(The form which I wish to refresh will already be open)

I have tried the following attached to a button closing the form - but get an error.

Is there a workaround? Many thanks Mark

Current code:

Code:
Forms!Me.txt_form_to_refresh.Requery
DoCmd.Close acForm, "frm_Log_Add_or_Edit"
 
Its been a while since I did any advanced VBA but I seem to recall you can do something like:

Code:
Forms(formname).Requery

So you should be able to substitute the name of your textbox control.

John
 
Thanks for that - I think the problem is that the form name is held in the textbox - so its how I extract that in a manner that the code likes?

Thanks Mark
 
Try

Code:
Forms(Me.txt_form_to_refresh).Requery
DoCmd.Close acForm, "frm_Log_Add_or_Edit"
 

That's the answer! - many many thanks.

Are you able to explain why

Forms(Me.txt_form_to_refresh).Requery works, but Forms!Me.txt_form_to_refresh.Requery doesn't.

Many thanks Mark
 
Its because using the exclamation mark syntax requires the actual form name, rather than a variable that references the name.

John
 
I cover the reason why in detail in thread
Thread702-1754662

But bottom line, if using the Bang operator it only works for named indices of a collection
Forms!YourFormName
me.controls!txtboxone

That is it. Does not work with variables or properties. Only named indices of a collection. Strongm's thread referenced in that thread gives some more detail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top