IsNull() in Subform, Trouble

  • Thread starter malik via AccessMonster.com
  • Start date
M

malik via AccessMonster.com

Hi
I have a Parent Form name "FrmDrVoucher" and a Subform (Continuous) name
"FrmDrVoucherBodySubForm".
I have a textfield control on subform name "TxtAccountNo"
The IsNull() function is not working.

I am using the following code in BeforeUpdate event of this control.

Private Sub TxtAccountNo_BeforeUpdate(Cancel As Integer)

If IsNull(Me.TxtAccountNo) Then
MsgBox ("Account No. is required")
DoCmd.CancelEvent
End If

End Sub

This Code is not working. I mean if the user do not fill it , it let the
cursor go in the next field.

Thank you
 
A

Anne

If IsNull(me.txtaccountno) then
me.txtaccountno.setFocus
msgbox "Account No is required"
Cancel = true
end if
end sub
 
J

John W. Vinson

Hi
I have a Parent Form name "FrmDrVoucher" and a Subform (Continuous) name
"FrmDrVoucherBodySubForm".
I have a textfield control on subform name "TxtAccountNo"
The IsNull() function is not working.

I am using the following code in BeforeUpdate event of this control.

Private Sub TxtAccountNo_BeforeUpdate(Cancel As Integer)

If IsNull(Me.TxtAccountNo) Then
MsgBox ("Account No. is required")
DoCmd.CancelEvent
End If

End Sub

This Code is not working. I mean if the user do not fill it , it let the
cursor go in the next field.

Thank you

You need to move your code from the txtAccountNo control's BeforeUpdate event
to the Form's BeforeUpdate event. The textbox's event will fire only if the
user types something into the textbox; if they open the form, ignore the
textbox completely, and move to a new record, the Form's BeforeUpdate event
will fire, but the textbox's won't.
 
M

malik via AccessMonster.com

Not working.
Cursor still moves to next field without any Msg.

If IsNull(me.txtaccountno) then
me.txtaccountno.setFocus
msgbox "Account No is required"
Cancel = true
end if
end sub
Hi
I have a Parent Form name "FrmDrVoucher" and a Subform (Continuous) name
[quoted text clipped - 17 lines]
Thank you
 
M

malik via AccessMonster.com

Ok.
Then plz tell me that how it is possible that if a user dont fill this txt
file, a new form opens with something.

can this possible.
????
Hi
I have a Parent Form name "FrmDrVoucher" and a Subform (Continuous) name
[quoted text clipped - 17 lines]
Thank you

You need to move your code from the txtAccountNo control's BeforeUpdate event
to the Form's BeforeUpdate event. The textbox's event will fire only if the
user types something into the textbox; if they open the form, ignore the
textbox completely, and move to a new record, the Form's BeforeUpdate event
will fire, but the textbox's won't.
 
J

John W. Vinson

Ok.
Then plz tell me that how it is possible that if a user dont fill this txt
file, a new form opens with something.

Presumably because you have an error in your code... which I cannot see.

Please post the actual code that you are using.
 
A

Anne

John is correct, I never doubted him, but I needed to work it out for myself.
I tested the before update event a the form and it works there. I tested it
on a single form.

However, if the field is a control on another subform and no data has been
entered on that subform, it does not fire because no record has been created.
Probably because the correct form has not been called.
 
M

malik via AccessMonster.com

Here is the Code
Private Sub TxtAccountNo_BeforeUpdate(Cancel As Integer)
If IsNull(Me.TxtAccountNo) Then
MsgBox ("Please Enter Party Code")
Cancel = True
End If

End Sub

It is a continuous Sub Form.

There is no code for other Controls.

Thank u.

John is correct, I never doubted him, but I needed to work it out for myself.
I tested the before update event a the form and it works there. I tested it
on a single form.

However, if the field is a control on another subform and no data has been
entered on that subform, it does not fire because no record has been created.
Probably because the correct form has not been called.
[quoted text clipped - 23 lines]
textbox completely, and move to a new record, the Form's BeforeUpdate event
will fire, but the textbox's won't.
 
B

BruceM via AccessMonster.com

Please read the responses carefully. The code needs to be in the *Form's*
Before Update event. The only way a text box Before Update event will run is
if the text box has been updated. If the user enters the text box, then
leaves without adding anything, there is no text box update, and the Before
Update code will not run. The only way it will show the message box, as the
code stands, is if the text box contains a value that the user deletes. In
that case the text box has been updated in such a way that it is Null.

You should be sure the table does not insert a default value in the field.
Also, if it is a text field, do not allow a zero-length string.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.TxtAccountNo) Then
MsgBox ("Please Enter Party Code")
Cancel = True
Me.txtAccountNo.SetFocus
End If

Here is the Code
Private Sub TxtAccountNo_BeforeUpdate(Cancel As Integer)
If IsNull(Me.TxtAccountNo) Then
MsgBox ("Please Enter Party Code")
Cancel = True
End If

End Sub

It is a continuous Sub Form.

There is no code for other Controls.

Thank u.
John is correct, I never doubted him, but I needed to work it out for myself.
I tested the before update event a the form and it works there. I tested it
[quoted text clipped - 9 lines]
 
J

John W. Vinson

Here is the Code
Private Sub TxtAccountNo_BeforeUpdate(Cancel As Integer)
If IsNull(Me.TxtAccountNo) Then
MsgBox ("Please Enter Party Code")
Cancel = True
End If

End Sub

It is a continuous Sub Form.

There is no code for other Controls.


You need to move your code from the txtAccountNo control's BeforeUpdate event
to the FORM'S BeforeUpdate event.

You need to move your code from the txtAccountNo control's BeforeUpdate event
to the FORM'S BeforeUpdate event.

You need to move your code from the txtAccountNo control's BeforeUpdate event
to the FORM'S BeforeUpdate event.

You need to move your code from the txtAccountNo control's BeforeUpdate event
to the FORM'S BeforeUpdate event.

You need to move your code from the txtAccountNo control's BeforeUpdate event
to the FORM'S BeforeUpdate event.

I don't know how to explain it any more clearly than that.
 

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