Wildcards in event procedure?

  • Thread starter Thread starter Phil Hood
  • Start date Start date
P

Phil Hood

Hi,

I'm trying to create some code that will check the name of
a control on a form. I want to include a wildcard in the
check. There are a set of controls on the form named:

1A, 2A, 3A, 4A, 5A

I select each of the controls in turn and then test as
follows:

If Me.Name = *A Then do something....

but it resulted in a message saying 'Compile error,
Expected: expression'

I thought the problem was because I hadn't enclosed *A in
quotes as follows (because the name of a control is a
string):

If Me.Name = "*A" Then do something....

This complied OK but when I run the code it does
not 'find' the control and trigger the 'then' statement.

Any ideas?

Phil.
 
In a query, you need to use Like instead of = in conjunction with wildcards.
However, in VBA, you can't use Like.

What you can do is check whether the last character of the name is an A:

If Right(Me.Name, 1) = "A" Then
 
Pardon me, but you can use the LIKE comparison operator in VBA. You have to be
careful with it since it can be case specific or not depending on how you have
set the modules Option Compare statement.

For instance in the immediate window I can enter
?"A" Like "*" and have it return True

More likely the problem is that the OP is testing the name of the form vice the
name of the control.

Me.Name will return the name of the form (or report)

ControlReference.Name will return the name of the control

Since the OP did not share all the code, it is difficult to be exact on how he
needs to change the reference.
 
Back
Top