Passing current form name to other form

owiec

New member
Local time
Today, 02:56
Joined
Nov 1, 2009
Messages
5
Hello,
Ive little problem with passing current form name to another form. I'm tring to execute something like this

Form1:
DoCmd.OpenForm "Form2", OpenArgs:="Form1"

Form2:
Private Sub Form_Load()

Me.Move OpenArgs.WindowLeft, OpenArgs.WindowTop
DoCmd.Close acForm, OpenArgs

End Sub

Ofcourse that doesn't work. Is there possibility to pass current form name which will work with .Parametr?

Thanks in advance!
 
Yes it is entirely possible to do what you want, your Docmd, should look like this;
Code:
DoCmd.OpenForm "FromName2", , , , , , Me.Form.Name
Me.Form.Name will return the name of the initiating form.

I'm not sure what you are trying to do with your second piece of code, but ultimately it seems you are trying to close the initiating form. If this is the case then you can just cut straight to the chase and use;
Code:
DoCmd.Close acForm, OpenArgs
 
Sorry, I should have said this earlier, Welcome to the forum.
 
You can't use openargs in the On Load event. It has to be in the On Open event.
 
Unfortunatly that doesnt work.

Form1:
Code:
Private Sub bNext_Click()
DoCmd.OpenForm "Form2", , , , , , Me.Form.Name
End Sub
Form2:
Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.Close acForm, OpenArgs
End Sub
Error:
Code:
Run-time error '424':
Object required

EDIT:
I forgot that is should me Me.OpenArgs. Its now working.

Thank you!
 
Last edited:
OpenArgs

Naw, OpenArgs exist for the lifetime of the form. These routines returned the correct values...
Code:
Private Sub CommandButton_Click()
   MsgBox Me.OpenArgs
End Sub

Private Sub Form_Close()
   MsgBox Me.OpenArgs
End Sub
In Access 2007.
 
You can't use openargs in the On Load event. It has to be in the On Open event.

Yes, I was incorrect due to the fact that I had experienced it once where I couldn't use it as it didn't persist for some reason, but not sure now why that was.
 
I have found in the past that you need to be careful about when you close the referring form when you are passing OpenArgs. The referring form needs to stay open until the OpenArgs have been collect by the opened form.
 

Users who are viewing this thread

Back
Top Bottom