invisible / visible forms

potts

Registered User.
Local time
Today, 00:05
Joined
Jul 24, 2002
Messages
87
I have a form (a) that can be opened through one of two others (b or c). I want the operation to work such that whichever form is used to open (a) is hidden / made invisible when (a) opens. This I have managed to do.

Now when I close (a), I want the form that opened (a) - either (b) or (c) to be made visible again.

This I am having trouble with.

can anyone help?
 
---message deleted as I found my reply was incorrect---
 
Last edited:
This is how I've solved the problem for myself.

I created a public function in a global module with a module-level variable.

Public frm As Form


Public Function OpenA(frmOpenedFrom As Form)

Set frm=frmOpenedFrom

DoCmd.OpenForm "A"

End Function

On the buttons of the other forms that opens A set the command to call this function with the forms name.

Then in the close button of A type:

Private Sub cmdButton_Click()

DoCmd.Close

frm.visible=True

set frm=nothing

End Sub
 
Use the OpenArgs argument of the OpenForm method to pass the name of the requesting form suchas:
Code:
DoCmd.OpenForm "FormA", acNormal, , , , , Me.Name

Now that the OpenArgs string contains the name of the requesting form we can then....

In the OnOpen event add:

Code:
Forms(Me.OpenArgs).Visible = False

And in the OnClose event of FormA put

Code:
Forms(Me.OpenArgs).Visible = True
 
I'm having a couple of problems with these methods...

Firstly, I can't get the OpenArgs method to work, but I think that is because I am using it already for another purpose.

Second. I'm struggling with the Public Function. I keep on getting an "argument not optional" mesage when I run it.

I like the idea of the Function method as I need the same thing to happen for several forms - i.e. the one form could open any of several others and the same visibility issue would apply. Can this function be modified so that it operates for any form, not just "a"?

Thanks for your help
 
I like Fornatian's idea but have never tried it. I realized I left something out looking back over my first reply.

In the function, you do have this in a global module and not the module of a form right,

Public Function OpenA(frmOpenedFrom As Form)

Set frm=frmOpenedFrom

frm.Visible=False

DoCmd.OpenForm "A"

End Function

Let me know if that fixes it.

In the buttons on the form of whatever you're going to open A from, type this in the On Click:

=OpenA([Forms]![Name of the current form you're going to open from])
 
Thanks, I'll try this when I get home.

how could I modify this code if I wanted to open more forms like "A" from the same form.

for example...

If I have a form with four command buttons, each of which opens a different form, and I want the visibility function to run regardless of which form I open.


Does this make any sense?

Thanks
 
Hey! You're really starting to explore the options vba gives you. This is how you could do it.

For opening:

Public Function OpenA(frmOpenedFrom As Form, strToOpen as String)

Set frm=frmOpenedFrom

frmOpenedFrom.Visible=False

DoCmd.OpenForm strToOpen

End Function

To assign this function type this "=OpenA([Forms]![Name of form opened from],"Name of form to open")"

Then you could create a reusable function to assign for closing:

Public Function CloseForm(strToClose as String)

DoCmd.Close acForm, strToClose

frm.Visible=True

Set frm=Nothing

End Function

Assign this function "=CloseForm("Name of form to close")"
 
Sorry Rob, still not having much luck.

It doesn't seem to like the =OpenA part. Any ideas?
 
Is it giving you a debug error message when you run it?

If so, what is it highlighting?
 
I keep getting a vbExclamation message saying ...

Compile Error:
Expected: line number or label or statement or end of statement
 
Do me a favor a paste ALL your code in here including the public variable.
 
Good News Rob. I got it working... All I needed to do was put an X in front of the = when calling the procedure.

That said...

The close form isn't working. It doesn't recognise the frm.Visible = false.

I get a message saying "Run time error '424': Object required"

I think I need to refer back to the OpenA module, but I don't know how.

Also, as an aside: is it possible to modify the OpenA module to control whether the form opens in add, or edit mode?

Thanks for your continuing help Rob
 

Users who are viewing this thread

Back
Top Bottom