1

Simple question, but I am new to databases. I have a field called 'ActorRetired?', and in some VBA code I need to set the value of it to -1. But When I try:

Me.ActorRetired?.Value = -1

I get the error 'Compile Error: Expected: Expression' with the question mark highlighted.

How do I refer to the field name without this error? So far I have tried

Me.[ActorRetired?].Value = -1
Me."ActorRetired?".Value = -1

But neither has worked. Please help!

1 Answers1

1

You can't have special characters in a VBA name. The bang operator ( the ! in Me![ActorRetired?] = -1) is just a shortcut for string based name lookup. It's not syntactically clear so I recommend using an actual string so it's clear that is what you want to do.

If you want to access the underlying Field using a string you would go through the form recordset like this:

Me.Recordset.Fields.Item("ActorRetired?").Value = -1

Or if you have a control of the same name you can go through the forms control collection like this:

Me.Controls.Item("ActorRetired?").Value = -1
HackSlash
  • 171
  • 6