closing previous form (1 Viewer)

cvaccess

Registered User.
Local time
Yesterday, 21:41
Joined
Jun 27, 2002
Messages
48
What is the easiest way to close a previous form when opening a new form?

I have tried macro and coding and both do not work for me. In the macro I first close the form then open the new form. Why doesn't this work?

In coding/modules, this is my code:

Private Sub Check16_GotFocus()
On Error GoTo Err_Check16_GotFocus

Dim Form1Name As String
Dim form2name As String
Dim LinkCriteria As String

Form1Name = "Selecting TP Variations"
form2name = "TP Analysis Selection"
DoCmd.OpenForm Form1Name, , , LinkCriteria
DoCmd.Maximize
DoCmd.Close acForm, form2name

Exit_Check16_GotFocus:
Exit Sub

Err_Check16_GotFocus:
MsgBox Error$
Resume Exit_Check16_GotFocus
End Sub

Why doesn't this work?

Thank you for your help.
 

Tim K.

Registered User.
Local time
Today, 04:41
Joined
Aug 1, 2002
Messages
242
Try the code below.

Private Sub cmdOpenNewForm_Click()
DoCmd.Close
DoCmd.OpenForm "YourNewFormName"
End Sub

I assume the command button called cmdOpenNewForm.
 

ghudson

Registered User.
Local time
Yesterday, 23:41
Joined
Jun 8, 2002
Messages
6,195
Using the name of Tim's button, this is how I open a form and close the form that contained the code...

Private Sub cmdOpenNewForm_Click()
DoCmd.OpenForm "YourFormNameHere"
DoCmd.Close acForm, Me.Name 'nice and generic
End Sub

The order of events prevents the user from seeing the first form close.

HTH
 

cvaccess

Registered User.
Local time
Yesterday, 21:41
Joined
Jun 27, 2002
Messages
48
ghudson,

I tried this and it didn't work. I get this error
"Runtime error '2585'. This action can't be carried out while processing a form or report event. A macro specified as the OnOpen, OnClose, OnFormat,OnRetreat, OnPage, or OnPrint property setting contains an invalid action for the property. When you click OK, an Action Failed dialog box will display the name of the macro that failed and its arguments."When I choose to debug it is highlighted on DoCmd.Close acForm, Me.Name. When I mouse over acForm it stated acForm=2. I do not have macros related to these forms.

Private Sub EDIPendsCheckbox_GotFocus()
DoCmd.OpenForm "Selecting TP Variations"
DoCmd.Close acForm, Me.Name
End Sub

Please help.

Thank you.
 

DW

Registered User.
Local time
Today, 04:41
Joined
May 25, 2002
Messages
58
I use this in my forms.

Private Sub Form_Load()
DoCmd.Close acForm, "frmsidemenu", acSaveYes
DoCmd.Close acForm, "frmpolicydetailsmenu", acSaveYes
End Sub

It works for me.

Perhaps if you attach a demo, we can help you. Only two of your forms are needed

Dave
 
R

Rich

Guest
You're using the OnFocus event, move the focus first or use the on click event
 

Users who are viewing this thread

Top Bottom