It's not possible. From the Help file:
Visual Basic Naming Rules
Use the following rules when you name procedures, constants, variables,
and arguments in a Visual Basic module:
- You must use a letter as the first character.
- You can't use a space, period (.), exclamation mark (!), or the
characters @, &, $, # in the name.
- Name can't exceed 255 characters in length.
- Generally, you shouldn't use any names that are the same as the
functions, statements, and methods in Visual Basic. You end up shadowing
the same keywords in the language. To use an intrinsic language function,
statement, or method that conflicts with an assigned name, you must
explicitly identify it. Precede the intrinsic function, statement, or
method name with the name of the associated type library. For example, if
you have a variable called Left, you can only invoke the Left function
using VBA.Left.
- You can't repeat names within the same level of scope. For example, you
can't declare two variables named age within the same procedure. However,
you can declare a private variable named age and a procedure-level
variable named age within the same module.
Note: Visual Basic isn't case-sensitive, but it preserves the
capitalization in the statement where the name is declared.
On the other hand, I don't see why you need to have the variable named the
same as the messed-up field name.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
LaRae said:
Here is the code that I am using:
Private Sub Short_Summary_BeforeUpdate(Cancel As Integer)
If Invoice/Contract# = DLookup("Invoice/Contract#", "Contractual_table",
"[Invoice/Contract#] = '" & Short_Summary & "'") Then
MsgBox "That contract number is already in use."
Cancel = True
Me.Short_Summary.SelStart = 0
Me.Short_Summary.SelLength = Len(Me.Short_Summary)
End If
End Sub
When it is compiled, VB puts a space on either side of the / on the first
invoice/contract#.
RoyVidar said:
<
[email protected]>:
Is there any way to use special characters in variables? I've
inherited a database with messed up field names and I want to use a
field name with a / in it as a variable. Is there a way to do this
without renaming the field?
I don't think you can use field names as variables. I think you can
refer to fields in a recordset, for instance like this
rs![my/crazyname]
rs("my/crazyname")
rs.fields("my/crazyname")
dim strFieldName as String
strFieldName = "my/crazyname"
rs.fields(strFieldName)
etc, and form controls the same way, just substitute rs with Me or the
more qualified Forms!frmFormName / Forms("frmFormName")
But do please tell what you intend to do, then we can probably assist.