coding problem

potts

Registered User.
Local time
Today, 08:43
Joined
Jul 24, 2002
Messages
87
I'm in the closing stages of creating my database, and as a tidy-up I want to control the visibility of forms that open other forms.

for example

If form "A" opened form "B", when "B" opens "A" becomes invisible, and when "B" closes "A" becomes visible again.


As this happens numerous times throughout the database I want to control all this in a public function.

Having received a great deal of help, I've ended up with the following:

Public Function Invisiblefrm(frmInvisible As Form, strToOpen As String)

frmInvisible.Visible = False

DoCmd.OpenForm strToOpen

End Function

'this is then assigned to an On_Click event with the following code:

x = Invisiblefrm([Forms]![FormOpenedFrom], "form to be opened")


Everything is running like clockwork to this point. However, on closing the opened form, I now need to reverse the process.

I tried doing this using another public function assigned in a similar manner to the Invisiblefrm function:

Public Function Back(strToClose As String)

DoCmd.Close acForm, strToClose

frmInvisible.Visible = True

End Function


This is where it all goes wrong. the frmInvisible line isn't too popular.... I keep getting a message telling me that the "variable is not defined" and frmInvisible is highlighed blue.

Can anyone help as this is really dragging out now, and the workload is piling up rapidly!!!


Thanks very much.
 
Hi Potts

I think your approach is elegant. I have a similar need to jump back and forth between forms, and might try this.

Now the reason your code isn't working, I believe, is a variable scope problem.

The variable frmInvisible is a local variable, which exists only within the function Invisiblefrm. It is defined each time the function is called, and is lost when the end of the function is reached.

To get around this problem you could either:
a) supply the form in your back function
eg Public Function Back(frmVisible as form, strToClose As String) or

b) store the value of frmInvisible in a global variable.

In the declarations section at the top of your module declare a global variable:

Public frmShowHide as form (this should have a different name to frmInvisible used in your function)

In function Invisiblefrm, set the value of this variable
set frmShowHide = frmInvisible

Then you can refer to frmShowHide in the Back function.

Hope this helps

Dan
 

Users who are viewing this thread

Back
Top Bottom