Proper way to close a form in the Form Load event

  • Thread starter Thread starter robert d via AccessMonster.com
  • Start date Start date
R

robert d via AccessMonster.com

I have a form that can be opened from a number of other forms. It displays
data for a certain item. Typically, this form is opened when someone double
clicks on the item in a list box on some forms and a tree on another form.

The Form Load event needs to check that the item actually exists (it is
possible that someone could delete the item while having one of these other
forms open and then try to double-click on the item after it has been deleted)
..

So in the Form Load event I set up a DAO recordset that selects the item from
the table. After the recordset, here is what I have:

If rsCHECK.RecordCount = 0 Then
MsgBox "Can't find item!", vbOKOnly + vbCritical
DoCmd.Close acForm, Me.Name
GoTo Exit_Sub
End If

Exit_Sub is the Exit Handler that includes closing the open recordset.

Is this the proper way to set this up.

Thanks in advance.
 
Hi Robert,

Try using the form's Open event. This has a Cancel parameter, so you can
do something like

...
If rsCHECK.RecordCount = 0 Then
Cancel = True
MsgBox blah blah
...
 
Actually, I think you will have to use the Forms RecordSetClone to check the
record count.

Cancel = (me.recordsetclone.recordcount = 0)
If Cancel the msgbox "blah, blah, blah"

HTH
Dale
 

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

Back
Top