![]() |
Userform doesn't recognize other user form upon re-load
It appears I can call and pass variables from one user form to another but
when I want to go close back to the originating user form to perform additional tasks it doesn't seem to recognize the original form when i try to load or show it. When I get the drop down for the form frmSearch it doesn't show the option to Hide or Show as a form normally would... Yet, this form loads okay when initially called from a command button on the worksheet. Any ideas of what I may be doing wrong? |
Userform doesn't recognize other user form upon re-load
Hi Cheryl,
I had written a reply, and just noticed i had forgotten to post it :-~, sorry. Not sure it applies to your case but: 1. When unloading a userform, say frmSearch, the userform is destroyed completely, therefore calling it again later (using the same name frmSearch) automatically creates a brand new userform, and since it is brand new, it also mean it is in the same state as if you were using the form for the 1st time in your project. Now, if you just Hide and call it again, it will show as when you left it last time. 2. a bit further: Think about a specific userform, eg frmSearch, as a template. When you call it, vba in fact doesn't work with the one you have designed, but with a copy of it. It just happens that Vba does a automatic step for you which can however be misleading: When you use the form in your code for the first time, say: frmSearch.Show Vba does: Dim frmSearch As frmSearch 'declare a variable of type frmSearch set frmSearch = New frmSearch ' Create the object (Initialize event fires) frmSearch.Show Basically vba enables you to work with a userform variable that has the same name than the 'template'. So when you unload the userform is destroyed and calling it again creates a brand new one. I just happens that it has the same name. You could give the userform variable any variable name: Dim frm1 as frmSearch Set frm1= new frmsearch frm1.show and in that case, the you have to do the steps yourself. A simple way to show that a userform is just a 'template' is to create 2 variables frm1 and frm2 as frmSearch , show the first one normally, then on frm1 ave a button that shows frm2... it will show several frmSeearch at the same time and each have their own status. 3. Finally. I believe you posted a question yesterday about userform. If i remember correctly: - frmSearchEntry is shown from a button on frmSearch - frmSearchEntry is automatically shown on first use Not sure exactly how it was, but here is what i would do: - Create a public Display sub in the frmSearch Public Sub Display() If <no search entry data yet, ie 2st time then 'use the If line above to determine whether or not 'frmSearchEntry needs to be displayed before frmSearch frmSearchEntry.Show End If Me.Show End Sub -Call this sub from a module: frmSearch.Display instead of frmSearch.Show -Then in the frmSearch, you can still have a button to display the frmSearch, but basically, when you want to show the Search one, call the Display method instead of the Show one so that you can process the context before really showing it. I hope it helps, Sebastien Well, in response to my own post.. I found a solution.. seems I need to create a procedure exclusively for this and call it.. Not sure why it was a problem still in the first place and why this works instead.. but it does... "Cheryl" wrote: It appears I can call and pass variables from one user form to another but when I want to go close back to the originating user form to perform additional tasks it doesn't seem to recognize the original form when i try to load or show it. When I get the drop down for the form frmSearch it doesn't show the option to Hide or Show as a form normally would... Yet, this form loads okay when initially called from a command button on the worksheet. Any ideas of what I may be doing wrong? |
All times are GMT +1. The time now is 07:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com