DOCmd.Close vs Tootlbar "Close"

G

Guest

I have a form with two unbound combo boxes. The combo boxes are used in the
Where close of the forms record source.

Select Field1, Field2
From tblMyTable
Where (([Field1] = Forms![MyForm]![Combo1]) AND ([Field2] =
Forms![MyForm]![Combo2]));

The user will select values for the combo boxes and press a command button
to refresh and requery the form.

Me.Refresh
Me.Requery

All works well until the form is closed. I have a command button on the
form for closing

DoCmd.Close acForm, "frmMyForm", acSaveNo

When this is pressed an access box is displayed requesting the value of
Forms![MyForm]![Combo1] and then a second one Forms![MyForm]![Combo1]

Even if I enter a valid value for both requests the system crashes. If I
use the File\Close commnd from the toolbar the form closes fine? Any
thoughts or assistance will b appreciated.
 
D

Dirk Goldgar

Justin said:
I have a form with two unbound combo boxes. The combo boxes are used
in the Where close of the forms record source.

Select Field1, Field2
From tblMyTable
Where (([Field1] = Forms![MyForm]![Combo1]) AND ([Field2] =
Forms![MyForm]![Combo2]));

The user will select values for the combo boxes and press a command
button to refresh and requery the form.

Me.Refresh
Me.Requery

If you're going to requery, why refresh first?
All works well until the form is closed. I have a command button on
the form for closing

DoCmd.Close acForm, "frmMyForm", acSaveNo

When this is pressed an access box is displayed requesting the value
of Forms![MyForm]![Combo1] and then a second one
Forms![MyForm]![Combo1]

Even if I enter a valid value for both requests the system crashes.
If I use the File\Close commnd from the toolbar the form closes fine?
Any thoughts or assistance will b appreciated.

I've seen this happen on occasion, but I don't recall exactly what
circumstances cause it. As a workaround, you could clear the form's
recordsource before closing it:

If Me.Dirty Then Me.Dirty = False ' save record if modified
Me.RecordSource = ""
DoCmd.Close acForm, "frmMyForm", acSaveNo
 
G

Guest

Dirk,

That's a good ideae. Thanks I'll try it.

Dirk Goldgar said:
Justin said:
I have a form with two unbound combo boxes. The combo boxes are used
in the Where close of the forms record source.

Select Field1, Field2
From tblMyTable
Where (([Field1] = Forms![MyForm]![Combo1]) AND ([Field2] =
Forms![MyForm]![Combo2]));

The user will select values for the combo boxes and press a command
button to refresh and requery the form.

Me.Refresh
Me.Requery

If you're going to requery, why refresh first?
All works well until the form is closed. I have a command button on
the form for closing

DoCmd.Close acForm, "frmMyForm", acSaveNo

When this is pressed an access box is displayed requesting the value
of Forms![MyForm]![Combo1] and then a second one
Forms![MyForm]![Combo1]

Even if I enter a valid value for both requests the system crashes.
If I use the File\Close commnd from the toolbar the form closes fine?
Any thoughts or assistance will b appreciated.

I've seen this happen on occasion, but I don't recall exactly what
circumstances cause it. As a workaround, you could clear the form's
recordsource before closing it:

If Me.Dirty Then Me.Dirty = False ' save record if modified
Me.RecordSource = ""
DoCmd.Close acForm, "frmMyForm", acSaveNo

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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