Object Required Error Message

  • Thread starter Thread starter jbyrnz via AccessMonster.com
  • Start date Start date
J

jbyrnz via AccessMonster.com

I have a combo box control for a yes/no field and a lookup table for the
yes/no field.

After Update I want Access to check the value and if it is -1, then I want a
text box to become visible and to have the focus and a message box to
indicate that the text box needs a value. When the user clicks OK on the
message box, I want the visible text box to have the focus and not let go of
the focus until a valid string is entered in the text box or the combo box is
updated again, back to the default value of 0. Then, I want the visible text
box to become invisible and the focus to go onto the next control.

This is my sub:

Private Sub ClaimYesNoCbo_AfterUpdate()
If Me!ClaimYesNoCbo = -1 And Me!ClaimIDTxt Is Null Then
Me.ClaimIDTxt.Visible = True
Me.ClaimIDTxt.SetFocus
MsgBox "You have indicated that this incident has been followed by a
claim. Please enter in a Claim Number for this claim."
End If
End Sub

No matter how I've tried to modify the code syntax I keep getting an 'Object
Required' error message, and I don't know why.

My questions are: What are some of the causes for this error message? What
can I try with my code that might eliminate the error message?
 
IS Null is SQL, you need to use the IsNull() function in VBA. Also, it is a
good habit to use constants and good indenting.

Private Sub ClaimYesNoCbo_AfterUpdate()
If Me!ClaimYesNoCbo = True And IsNull(Me!ClaimIDTxt) Then
Me.ClaimIDTxt.Visible = True
Me.ClaimIDTxt.SetFocus
MsgBox "You have indicated that this incident has been followed
by a claim. Please enter in a Claim Number for this claim."
End If
End Sub
 
Thank you for your reply:
IS Null is SQL, you need to use the IsNull() function in VBA. Also, it is a
good habit to use constants and good indenting.

Private Sub ClaimYesNoCbo_AfterUpdate()
If Me!ClaimYesNoCbo = True And IsNull(Me!ClaimIDTxt) Then
Me.ClaimIDTxt.Visible = True
Me.ClaimIDTxt.SetFocus
MsgBox "You have indicated that this incident has been followed
by a claim. Please enter in a Claim Number for this claim."
End If
End Sub

I replaced my sub syntax with this syntax and tested it out, but I can't tell
what happened. The ClaimIDTxt text box did not become visible, and the
message box did not appear. Is there something else that I might be able to
do to test if I am missing an integral piece of code? Is AfterUpdate the
right event to use? I can't find any reason why not, but I'm new at this and
could be overlooking something.
 
The After Update event is the correct place to do this.
Put a breakpoint on this line:
If Me!ClaimYesNoCbo = True And IsNull(Me!ClaimIDTxt) Then

And see what the value of combo and the text box are.
 
I was about to try your breakpoint idea, but I thought I'd test it again. It
didn't work, but then I noticed that the "[Event Procedure]" value was
missing from the "After Update" property on the control. I added that value,
then I looked at the code and everything appeared good, after a quick glance,
but then I realized that it was creating a new sub. I knew something was
wrong. I deleted the new sub and tried it again. When the same thing happened
again I discovered what the problem was. Somehow, when I changed the name of
the control in the property sheet and I must not have saved it. So, the old
name was on the form object, and the code was referring to the new name of
the control. So, what it all comes down to is: USER ERROR : )

Thank you very much for helping me discover the problem. I really appreciate
that.
 
Back
Top