module code to close a form does not work

A

Angus Comber

Hello

I have a form called NewPolicy. On this form is a button which calls some
VBA code. At the end of the code is the line:

DoCmd.Close acForm, [Forms]![NewPolicy], acSaveNo

But this line does not close the form! What am I doing wrong?

Angus
 
D

Douglas J. Steele

The Close method is looking for the name of the object to close, not a
reference to it.

Try:

DoCmd.Close acForm, "NewPolicy", acSaveNo
 
J

John Vinson

Hello

I have a form called NewPolicy. On this form is a button which calls some
VBA code. At the end of the code is the line:

DoCmd.Close acForm, [Forms]![NewPolicy], acSaveNo

But this line does not close the form! What am I doing wrong?

Angus

You're not passing the *name of the form as a text string* in the
second argument of the Close event - you're passing the Form as an
object.

Use either

DoCmd.Close acForm, "NewPolicy", acSaveNo

or (more flexibly)

DoCmd.Close acForm, Me.Name, acSaveNo


John W. Vinson[MVP]
 

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