On Exit Event

A

alex

On Exit Event

Hello,

I have a form that opens to a new record. I set the focus to a
control that I want the user to populate without going any further.

This code below will not work, however, because the record has yet to
be created:

Private Sub comSubject_BeforeUpdate(Cancel As Integer)

If IsNull(Me.comSubject) Then
MsgBox "You cannot leave the [Subject] field empty!"
Cancel = True
Me.Undo
End If

I suppose I could add a default value or make the record dirty, but
that seems unnecessary.

This code works too well; I can’t move anywhere until I populate the
control:

Private Sub comSubject_Exit(Cancel As Integer)

'If IsNull(Me.comSubject) Then
' MsgBox "You cannot leave the [Subject] field empty!"
' Cancel = True
' Me.Undo
'End If

What I would like to do is not allow the user to continue (like the
exit code example) except if he/she wants to go to another record
(using the navigation buttons at the bottom of the form), essentially
canceling the creation of a new record.

Can I do that?
alex
 
J

Jeanette Cunningham

You can use the enter event of every other editable control on the form like
this
If IsNull(Me.comSubject) Then
MsgBox "Fill in the subject first"
DoCmd.CancelEvent
End If

You may need code to prevent users going back to the subject field and
making it null after they have filled out other fields.

A different approach:
You could also pop up a form with just one textbox for the subject.
User can't go any further until the fill out the subject.
After they have, you open the main popup with the subject filled in from the
first popup form.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


On Exit Event

Hello,

I have a form that opens to a new record. I set the focus to a
control that I want the user to populate without going any further.

This code below will not work, however, because the record has yet to
be created:

Private Sub comSubject_BeforeUpdate(Cancel As Integer)

If IsNull(Me.comSubject) Then
MsgBox "You cannot leave the [Subject] field empty!"
Cancel = True
Me.Undo
End If

I suppose I could add a default value or make the record dirty, but
that seems unnecessary.

This code works too well; I can’t move anywhere until I populate the
control:

Private Sub comSubject_Exit(Cancel As Integer)

'If IsNull(Me.comSubject) Then
' MsgBox "You cannot leave the [Subject] field empty!"
' Cancel = True
' Me.Undo
'End If

What I would like to do is not allow the user to continue (like the
exit code example) except if he/she wants to go to another record
(using the navigation buttons at the bottom of the form), essentially
canceling the creation of a new record.

Can I do that?
alex
 
A

alex

You can use the enter event of every other editable control on the form like
this
If IsNull(Me.comSubject) Then
    MsgBox "Fill in the subject first"
    DoCmd.CancelEvent
End If

You may need code to prevent users going back to the subject field and
making it null after they have filled out other fields.

A different approach:
You could also pop up a form with just one textbox for the subject.
User can't go any further until the fill out the subject.
After they have, you open the main popup with the subject filled in from the
first popup form.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


On Exit Event

Hello,

I have a form that opens to a new record.  I set the focus to a
control that I want the user to populate without going any further.

This code below will not work, however, because the record has yet to
be created:

Private Sub comSubject_BeforeUpdate(Cancel As Integer)

If IsNull(Me.comSubject) Then
    MsgBox "You cannot leave the [Subject] field empty!"
    Cancel = True
    Me.Undo
End If

I suppose I could add a default value or make the record dirty, but
that seems unnecessary.

This code works too well; I can’t move anywhere until I populate the
control:

Private Sub comSubject_Exit(Cancel As Integer)

'If IsNull(Me.comSubject) Then
'    MsgBox "You cannot leave the [Subject] field empty!"
'    Cancel = True
'    Me.Undo
'End If

What I would like to do is not allow the user to continue (like the
exit code example) except if he/she wants to go to another record
(using the navigation buttons at the bottom of the form), essentially
canceling the creation of a new record.

Can I do that?
alex

Jeanette, that's a good idea...
and the before update event will take care of the going back and
changing value to null issue.
Thanks,
alex
 

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