Closed Form not closed

bstice

Registered User.
Local time
Today, 13:21
Joined
Jul 16, 2008
Messages
55
Hello all,

I have a button that opens another form (form 2) and has code in it to close the current form (form 1). Form 2 kicks off some VBA in the on open procedure to delete form 1. Everytime I run the code, I get an error message that it cannot delete form 1 because it is still open. What am I missing here? THanks for help. I always award reputation points.

Brennan
 
Try closing form1 and then open form2
Private Sub Command0_Click()

DoCmd.Close
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub
 
Why are you trying to *delete* a form?
 
Try closing form1 first and then open form2
Private Sub Command0_Click()

DoCmd.Close
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub:)
 
Thanks for the responses. I am deleting the form, and then importing an updated form in its place.
Rapsr59 - I'll try your code and see if it works. Right now, I have similar code, but hopefully your's is better than what I have. Thanks

Brennan
 
I still get the error that I listed above. Any reason why a form would stay open why code is being run? Thanks

Brennan
 
Try adding some DoEvents to the next form to give Access a chance to complete the closing of the form.
 
It's too quick. Access is still closing the first form when it's asked to delete it.

Try doing a DoCmd.RepaintObject or a message box or something to slow the system down a little before deleting the first form.
 
OK - I Got It!


Enter the following in Form2 - Open Event

Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 1
End Sub

Enter the following in Form2 - On Timer Event

Private Sub Form_Timer()
Me.TimerInterval = 0
DoCmd.DeleteObject acForm, "Form1"
End Sub

I just tried it and It works

Richard
 
OH!

I did use the following when closing Form1

DoCmd.Close
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Form2"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 

Users who are viewing this thread

Back
Top Bottom