Cant Close form after opening another form???

D

Dave Elliott

My main form is named BlankChecks and below is the on click code to open the
form BlankChecksNotclr from the main form and should close the main form
BlankChecks
but it does not close the main form, why???

On Error GoTo Err_Command145_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "BlankChecksnotclr"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name



Exit_Command145_Click:
Exit Sub

Err_Command145_Click:
MsgBox err.Description
Resume Exit_Command145_Click
 
J

Jim/Chris

Try using this for the close command line

DoCmd.Close acForm, "FormName"

don't use ME.
Me refers to the current form in focus which is the one you
just opened.
Jim
 
M

M Skabialka

Because Me.Name is now the last opened, and currently active, form. You
must specify the name of the form to close if you have opened another form.

HTH
Mich
 
V

Van T. Dinh

Not quite, Mich.

"Me" refers to the Form in whose context the code the code is executed (if
you like, whose Module the code resides in), even if the Form is not the
currently active Form.

I use DoCmd.Close acForm, Me.Name all the time after I open another Form
without any problem. The advantage is that I don't have to change the
statement if I need to change the Form's name.

Me.Name is not the problem in the O.P.'s code but I can't see what's wrong.

HTH
Van T. Dinh
MVP (Access)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top