gotocontrol question

L

Lauri

I'm using Access 2000 on Windows XP (but needs to run on several OSs). I
have a form with a field that needs to have data entered. I've set the On
Exit property to run a macro if it is null.

The macro displays a message (msgbox).
The next line of the macro is gotocontrol with the property set to the
control name.

The macro runs with no errors, but the cursor is flashing in the next field.

What simple silly step am I missing to make the cursor set back into the
field I want the user to enter data into?

-Lauri
 
F

fredg

I'm using Access 2000 on Windows XP (but needs to run on several OSs). I
have a form with a field that needs to have data entered. I've set the On
Exit property to run a macro if it is null.

The macro displays a message (msgbox).
The next line of the macro is gotocontrol with the property set to the
control name.

The macro runs with no errors, but the cursor is flashing in the next field.

What simple silly step am I missing to make the cursor set back into the
field I want the user to enter data into?

-Lauri

Lauri,
It's been too long since I've used a macro, so I can't help there.
Use code instead. It's easy.

On the Control's BeforeUpdate event line write:
[Event Procedure]
Then click on the button with the 3 dots that will appear on that
line.
When the event code window opens, there will be 2 existing lines.
Between those 2 lines write:

If IsNull([ControlName]) Then
MsgBox "You must enter data in this field."
Cancel = true
End If

The Cancel argument will cancel the event and cause the same control
to get the focus back.

When completed the entire event code will look like this:

Private Sub ControlName_BeforeUpdate(Cancel As Integer)
If IsNull([ZIP]) Then
MsgBox "You must enter data in this field."
Cancel = True
End If
End Sub

However, you need to do this a bit differently if you are creating a
new record and want to assure that data has been entered into this
field. (The above code is for when someone enters that field, but
won't fire if the field is never entered.)

Code the Form's BeforeUpdate event:
(Use the same method as above to get into that event's code window.)

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([ControlName]) Then
MsgBox 'You must enter data in this field."
Cancel = True
[ControlName].SetFocus
End If
End Sub

Hope this helps.
 
L

Lauri

Thank you so much. That was trick I needed.
-Lauri

fredg said:
I'm using Access 2000 on Windows XP (but needs to run on several OSs). I
have a form with a field that needs to have data entered. I've set the On
Exit property to run a macro if it is null.

The macro displays a message (msgbox).
The next line of the macro is gotocontrol with the property set to the
control name.

The macro runs with no errors, but the cursor is flashing in the next field.

What simple silly step am I missing to make the cursor set back into the
field I want the user to enter data into?

-Lauri

Lauri,
It's been too long since I've used a macro, so I can't help there.
Use code instead. It's easy.

On the Control's BeforeUpdate event line write:
[Event Procedure]
Then click on the button with the 3 dots that will appear on that
line.
When the event code window opens, there will be 2 existing lines.
Between those 2 lines write:

If IsNull([ControlName]) Then
MsgBox "You must enter data in this field."
Cancel = true
End If

The Cancel argument will cancel the event and cause the same control
to get the focus back.

When completed the entire event code will look like this:

Private Sub ControlName_BeforeUpdate(Cancel As Integer)
If IsNull([ZIP]) Then
MsgBox "You must enter data in this field."
Cancel = True
End If
End Sub

However, you need to do this a bit differently if you are creating a
new record and want to assure that data has been entered into this
field. (The above code is for when someone enters that field, but
won't fire if the field is never entered.)

Code the Form's BeforeUpdate event:
(Use the same method as above to get into that event's code window.)

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([ControlName]) Then
MsgBox 'You must enter data in this field."
Cancel = True
[ControlName].SetFocus
End If
End Sub

Hope this helps.
 

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