On Close

M

Manuel

HI:

I have a form with a check box and a text box on it. To close the form the
user clicks the "X" located at the top right of the form.

What I'd like to do is have code that executes on the On Close event which
does not close the form if the user has checked the check box but has not put
anything in the text box.

I know I could accomplish this with a command button by having the command
button only close the form if certain conditions are met, but I don’t want to
add a command button to the form, I want the only option for closing the form
to be the “Xâ€.

Does anyone have any suggestions for how I would go amount accomplishing this.

Here’s what I have so far. The Cancel = True code does not work here; I
don’t think it’s appropriate:

Private Sub Form_Close(Cancel)

If Me.ckbxBetween = True And Me.txtInvIn.Value = "" Then
MsgBox "No Investor ID's Selected. Select Investot ID's or uncheck
""""Between"""" checkbox.", vbCritical, MsgBxTitle
Cancel = True
Exit Sub
End If
 
S

Stuart McCall

Manuel said:
HI:

I have a form with a check box and a text box on it. To close the form
the
user clicks the "X" located at the top right of the form.

What I'd like to do is have code that executes on the On Close event which
does not close the form if the user has checked the check box but has not
put
anything in the text box.

I know I could accomplish this with a command button by having the command
button only close the form if certain conditions are met, but I don't want
to
add a command button to the form, I want the only option for closing the
form
to be the "X".

Does anyone have any suggestions for how I would go amount accomplishing
this.

Here's what I have so far. The Cancel = True code does not work here; I
don't think it's appropriate:

Private Sub Form_Close(Cancel)

If Me.ckbxBetween = True And Me.txtInvIn.Value = "" Then
MsgBox "No Investor ID's Selected. Select Investot ID's or uncheck
""""Between"""" checkbox.", vbCritical, MsgBxTitle
Cancel = True
Exit Sub
End If

The form close event doesn't supply you with a Cancel parameter, however the
form unload event does. Your code looks fine to me (syntactically correct
anyway), so just move your code to the unload event and all should be ok.
 
L

Linq Adams via AccessMonster.com

If you don't want the form to close if the checkbox is checked but the
textbox is empty, then you also don't want to move to another record if the
checkbox is checked but the textbox is empty. This type of validation code
always needs to be in the form's BeforeUpdate event. Always!
 

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