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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call subroutine behind form from different form 1

Status
Not open for further replies.

votegop

Technical User
Feb 22, 2002
127
US
I have a popup form that comes up in front of the main form.

The main form has a public subroutine that "refreshes" the data on the main form.

I want to execute the "refresh" sub just after the popup closes. How do I execute a subroutine behind one form from code behind another?

Is there an easy way to do this without moving everything into modules?

All help greatly appreciated.

Jay
 
Hi!

As long as it's public, it should be available. For instance something like this might work:

[tt]Forms!MyForm.MyRefresh[/tt]

MyRefresh is name of the public sub
MyForm is name of the form where the public sub resides

Else, if you are opening the popup from the main form, using acdialog might also give some possibilities:

[tt]docmd.openform, "MyPopUp",,,,,acDialog[/tt]

You could then just execute the refresh on the line after, cause opening the form in dialog mode also halts the code execution in the main form until the popup form is closed.

HTH Roy-Vidar
 
Thanks very much for the help Roy-Vidar! Unfortunately, my results weren't so good.

The prior resulted in: "object doesn't support this property or method"

The latter resulted in: "Compile error: invalid use of property"

 
Hi again!

In the first case, I've tested it on a97 thru axp, and as long as the form, in which the public function is written/resides, is open it does work on my computers. To be on the safe side, you might consider using the function provided in Rohdems excellent faq faq181-320 to check whether the form is open. Paste the whole function in to a module (not a forms module) and use for instance someting like this prior to calling the public sub in your other sub:

[tt]If IsLoaded("NameOfFormWithFunction") Then
' do your function call
else
msgbox "form isn't open try again later.."
end if[/tt]

In the latter case, this is the means to open the popupform, you have substituted "mypopup" with the name of your form? If you don't specify any other arguments, it's 5 commas between the "openform myform" and acdialog, else check the help files for the correct syntax.

If you do require further assistance, in addition to the errormsg, please also provide the actual code you're using and the event in which you are invoking the code.

Roy-Vidar
 
Oups 2 - in the latter case, I've added a comme before the name of the form, which should not have been there. Correct syntax would be more like this:

[tt]docmd.openform "MyPopUp",,,,,acDialog[/tt]

Sorry, Roy-Vidar
 
Roy-Vidar:

I thought I'd graduated from VBA-Freshman to VBA-Sophmore. I was wrong. My public sub is also used in the on-click event of a button. Thus the name is "RefreshButton_Click". I was leaving off the "_Click" when I attempted to call it.

Thanks for your persistence. Your post convinced me that the answer had to be under my nose - and it was. Happy Holidays & thanks again!

Jay [santa]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top