Form BeforeUdate not behaving

G

Guest

I have the following BeforeUpdate event happening on a form

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[ObjectNum]) = True Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

Person comes to form, enters data and closes the form with a Button Control.

The even above shows up in the form's beforeUpdate property

The field is left blank. The user closes the form. The msg box shows up
fine. But when one choosees OK, it pops up again. After the seconfd time, the
form closes.

I was expecting the form to pop up message, choose OK, have focus placed on
required field, and enter the missing data.

What am I missing.

Thanks alot!
 
R

ruralguy via AccessMonster.com

Any chance your [ObjectNum] control and the field are named the same? It can
confuse Access.

Also try this code instead:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.ObjectNum & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.ObjectNum.SetFocus
Cancel = True
End If
End Sub

You do not need brackets unless there is an embedded space in the name.


G-Man said:
I have the following BeforeUpdate event happening on a form

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[ObjectNum]) = True Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

Person comes to form, enters data and closes the form with a Button Control.

The even above shows up in the form's beforeUpdate property

The field is left blank. The user closes the form. The msg box shows up
fine. But when one choosees OK, it pops up again. After the seconfd time, the
form closes.

I was expecting the form to pop up message, choose OK, have focus placed on
required field, and enter the missing data.

What am I missing.

Thanks alot!
 
G

Guest

Thanks for the response.

Same thing with your code. Msg comes up, and, at the same time, cursor goes
to filed specified by focus. Say OK to message, it repeats. Say OK the second
time, and the form exits.

The field name is from the table specified in the query the rom is built on.
The Name of the form Object is differnet than that name.

Again. Normal crash 1. I close form with nothing in field 2. Message box
comes up and cursor goes to required field. 3. I choose "OK" on the message
box 4. It pops up again. 4. I choose OK again, the form disappears.

What can I be missing




ruralguy via AccessMonster.com said:
Any chance your [ObjectNum] control and the field are named the same? It can
confuse Access.

Also try this code instead:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.ObjectNum & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.ObjectNum.SetFocus
Cancel = True
End If
End Sub

You do not need brackets unless there is an embedded space in the name.


G-Man said:
I have the following BeforeUpdate event happening on a form

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[ObjectNum]) = True Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

Person comes to form, enters data and closes the form with a Button Control.

The even above shows up in the form's beforeUpdate property

The field is left blank. The user closes the form. The msg box shows up
fine. But when one choosees OK, it pops up again. After the seconfd time, the
form closes.

I was expecting the form to pop up message, choose OK, have focus placed on
required field, and enter the missing data.

What am I missing.

Thanks alot!
 
R

ruralguy via AccessMonster.com

Put this code in the Form Unload event as well.

G-Man said:
Thanks for the response.

Same thing with your code. Msg comes up, and, at the same time, cursor goes
to filed specified by focus. Say OK to message, it repeats. Say OK the second
time, and the form exits.

The field name is from the table specified in the query the rom is built on.
The Name of the form Object is differnet than that name.

Again. Normal crash 1. I close form with nothing in field 2. Message box
comes up and cursor goes to required field. 3. I choose "OK" on the message
box 4. It pops up again. 4. I choose OK again, the form disappears.

What can I be missing
Any chance your [ObjectNum] control and the field are named the same? It can
confuse Access.
[quoted text clipped - 35 lines]
 
G

Guest

Thanks afain for the help!

Here's what I now have, pasted from the code. Have tried with the brackets
around the field name on the form, and without. I get the same thing. I
have verified the code is there! No difference.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.[ObjectNum] & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

Private Sub Form_Close()
If Len(Me.[2] & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

ruralguy via AccessMonster.com said:
Put this code in the Form Unload event as well.

G-Man said:
Thanks for the response.

Same thing with your code. Msg comes up, and, at the same time, cursor goes
to filed specified by focus. Say OK to message, it repeats. Say OK the second
time, and the form exits.

The field name is from the table specified in the query the rom is built on.
The Name of the form Object is differnet than that name.

Again. Normal crash 1. I close form with nothing in field 2. Message box
comes up and cursor goes to required field. 3. I choose "OK" on the message
box 4. It pops up again. 4. I choose OK again, the form disappears.

What can I be missing
Any chance your [ObjectNum] control and the field are named the same? It can
confuse Access.
[quoted text clipped - 35 lines]
Thanks alot!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
G

Guest

Sorry, here's the correct code pasted.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.[Objectnum] & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

Private Sub Form_Close()
If Len(Me.[ObjectNum] & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

ruralguy via AccessMonster.com said:
Put this code in the Form Unload event as well.

G-Man said:
Thanks for the response.

Same thing with your code. Msg comes up, and, at the same time, cursor goes
to filed specified by focus. Say OK to message, it repeats. Say OK the second
time, and the form exits.

The field name is from the table specified in the query the rom is built on.
The Name of the form Object is differnet than that name.

Again. Normal crash 1. I close form with nothing in field 2. Message box
comes up and cursor goes to required field. 3. I choose "OK" on the message
box 4. It pops up again. 4. I choose OK again, the form disappears.

What can I be missing
Any chance your [ObjectNum] control and the field are named the same? It can
confuse Access.
[quoted text clipped - 35 lines]
Thanks alot!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
R

ruralguy via AccessMonster.com

You need to use the form Unload event, *not* the Close event.

G-Man said:
Sorry, here's the correct code pasted.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.[Objectnum] & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub

Private Sub Form_Close()
If Len(Me.[ObjectNum] & "") = 0 Then
MsgBox "This field is required. Please Enter"
Me.[ObjectNum].SetFocus
Cancel = True
End If
End Sub
Put this code in the Form Unload event as well.
[quoted text clipped - 18 lines]
 

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

Similar Threads


Top