Before Update Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I put the following code into my BeforeUpdate event and I'm getting the
following error message:

Run Time error '2465'
Microsoft Office Access can't find the field 'txtThis' referred to in your
expression.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!txtThis & Me!txtThat & Me!txtTheOther & Me!txtWho _
& Me!txtWhat & Me!txtIDontKnow = "" Then
Cancel = True
MsgBox "You must fill out every field in this form", vbOKOnly
End If
End Sub

HELP!
 
Karen said:
I put the following code into my BeforeUpdate event and I'm getting
the following error message:

Run Time error '2465'
Microsoft Office Access can't find the field 'txtThis' referred to in
your expression.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!txtThis & Me!txtThat & Me!txtTheOther & Me!txtWho _
& Me!txtWhat & Me!txtIDontKnow = "" Then
Cancel = True
MsgBox "You must fill out every field in this form", vbOKOnly
End If
End Sub

HELP!

The error pretty much explains itself. If you do not have either a field or a
control on the form with that exact name then you will get that message. Are
you sure you spelled it correctly.

By the way your code will NOT do what you want it to. You will only get the
MsgBox if ALL fields were left empty (I assume you want it if even one field was
left empty). Plus testing for "" will not catch Nulls which is more likely to
be the case.

You need something like...

If Len(Nz(Me!txtThis,"")) = 0 _
Or Len(Nz(Me!txtThat,"")) = 0 _
Or ...
 
Thank you for your help Rick - I'm still having problems. I'm sure it's
something I'm doing wrong. Would you be so kind to give me the code exactly
how it should be so I can copy and paste it into the BeforeUpdate event? I
hope this isn't asking too much. Thank you
 
Karen said:
Thank you for your help Rick - I'm still having problems. I'm sure
it's something I'm doing wrong. Would you be so kind to give me the
code exactly how it should be so I can copy and paste it into the
BeforeUpdate event? I hope this isn't asking too much. Thank you

"Rick Brandt" wrote:

Private Sub Form_BeforeUpdate(Cancel as Integer)

If Len(Nz(Me!txtThis, "")) = 0 _
Or Len(Nz(Me!txtThat, "") = 0 _
Or Len(Nz(Me!txtTheOther, "")) = 0 _
Or Len(Nz(Me!txtWho, "")) = 0 _
Or Len(Nz(Me!txtWhat, "")) = 0 _
Or Len(Nz(Me!txtIDontKnow, "")) = 0 Then
MsgBox "You must fill out every field in this form", vbOKOnly
Cancel = True
End If

End Sub
 
Thanks for your help - Although, when I paste the code into my BeforeUpdate
event, 6 lines of code changes to red. Starting with "If Len(Nz(Me!txtThis,
"")) = 0 _"

Why is this happening?
Thank you, Karen
 
Back
Top