gotocontrol question

  • Thread starter Thread starter Lauri
  • Start date Start date
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
 
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.
 
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.
 
Back
Top