By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,486 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,486 IT Pros & Developers. It's quick & easy.

hiding field in form if null and give msgbox if not null

P: 8
Good day,
I have a form (CSearch) to input data and search for records in a query and displays it on a subform (CAff) once a search button is clicked.

I have a current event on the subform that check if the field "CONTRACTSTATUS" is "Expired" and if so gives a message box saying "This contract is expired"

This works when the main form has been loaded already, but whenever I re-open the form I get error 2424 "The expression you entered..."

Can you help me? Here is the code I'm using:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me.NewRecord Then
  3. Me!CONTRACTSTATUS.Visible = True
  4. End If
  5. If Me.CONTRACTSTATUS.Value = "EXPIRED" Then
  6. MsgBox ("This contract is expired")
  7. Else
  8. Me!CONTRACTSTATUS.Visible = False
  9. Exit Sub
  10. End If
  11. End Sub
Nov 1 '13 #1

✓ answered by NeoPa

Thank you.

I expect that means that the subform is using a recordset that is non-updatable. In such a case, when the main form has not yet been used to specify the search, there are no records in the subform at all. As it's not updatable there is not even any possibility of it being at the New Record position. From here Me.CONTRACTSTATUS.Value has no meaning as there is no current record from which it can take context.

In short, your code needs first to check if there is a current record before it tries to refer to it.

I hope that helps, and I'm a little confused that, in such a scenario, it would even trigger the Current event. Check out that idea anyway and see what you find.

Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Please could you include the full error message and the number of the line of code wher it occurs.
Nov 1 '13 #2

P: 8
Run-time error '2424':

"The expression you entered has a field, control, or property name that toolbox can't find"

And when I click on Debug, line # 5 is highlighted.
Nov 1 '13 #3

NeoPa
Expert Mod 15k+
P: 31,186
Thank you.

I expect that means that the subform is using a recordset that is non-updatable. In such a case, when the main form has not yet been used to specify the search, there are no records in the subform at all. As it's not updatable there is not even any possibility of it being at the New Record position. From here Me.CONTRACTSTATUS.Value has no meaning as there is no current record from which it can take context.

In short, your code needs first to check if there is a current record before it tries to refer to it.

I hope that helps, and I'm a little confused that, in such a scenario, it would even trigger the Current event. Check out that idea anyway and see what you find.
Nov 1 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.