Need help with this, please.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have been trying to stop users to make changes entries in a custom
calendar control that updates another form.
The control is "Scheduled" and should NOT be edited if entry is like=

"9999-Jones-W-1"

I tried many things, the last one is:

Private Sub Form_Current()
If Me!Scheduled = "*-?-*" Then
Me!Scheduled.Locked = True
Else
Me!Scheduled.Locked = False
End If
End Sub

I even tried:

Private Sub Scheduled_Click()
If Me!Scheduled = "*-?-*" Then
MsgBox "DO NOT make changes to Scheduled if it's related to a Job Example:
9999-Jones-W-1 "
End If
End Sub
(Not a perfect solution, even if it had worked)

Anyway any help is really appreciated, as you probably guessed I am a newbie.

Thanks in advance,
Emilio
 
Wind54Surfer said:
I have been trying to stop users to make changes entries in a custom
calendar control that updates another form.
The control is "Scheduled" and should NOT be edited if entry is like=

"9999-Jones-W-1"

I tried many things, the last one is:

Private Sub Form_Current()
If Me!Scheduled = "*-?-*" Then
Me!Scheduled.Locked = True
Else
Me!Scheduled.Locked = False
End If
End Sub


If you use wildcard characters in a comparison, you have to
use the Like operator instead of = Also, the ? wildcard
only matches a single character. I think this might be what
you want:

Private Sub Form_Current()
Me!Scheduled.Locked Like "*-*-*"
End Sub

OTOH, if the first four characters are always four digits,
then this would be a little safer:

Me!Scheduled.Locked Like "####-*-*"

Check Help for details.
 
Thanks for the prompt answer,

I used:

Me!Scheduled.Locked Like "*-*-*"

but I get: "Expected: expression"
(highlited is the word "Like")
I checked Help but don't see what's wrong.

Thanks again,
Emilio
 
Wind54Surfer said:
I used:

Me!Scheduled.Locked Like "*-*-*"

but I get: "Expected: expression"
(highlited is the word "Like")
I checked Help but don't see what's wrong.


Sorry, I left out part of the expression. Try this:

Me!Scheduled.Locked = Me!Scheduled Like "*-*-*"
 
Emilio,
I think Marsh meant:
If Me!Scheduled Like "*-*-*" Then
Me!Scheduled.Locked = True

or maybe
Me!Scheduled.Locked = (Me!Scheduled Like "*-*-*")
 
Thanks again, it works now except that when
I touch the last line (*-to enter new record)

I get: "Type mismatch"

any ideas?

Many thanks,
Emilio
 
Thanks to all of you!

I tried:

If Me!Scheduled Like "*-*-*" Then
Me!Scheduled.Locked = True

and that solved the "Type mismatch" problem

Thanks a lot,
Emilio
 
Wind54Surfer said:
Thanks again, it works now except that when
I touch the last line (*-to enter new record)

I get: "Type mismatch"

Arghhh. Such a simple problem and I make a mess of it not
once, but twice. AARRRgggghhhhh

The new record's Scheduled field doesn't have a value (i.e.
it's Null), so the expression to the right of the = sign is
also Null. The message is because the Locked property can
not be set to Null. The simplistic answer to this issue is
to use the If ... Then that Dan posted. Technically, you
should not really rely on the If <Null value> doing what you
want, so a more thorough way is:

Me!Scheduled.Locked = Nz(Me!Scheduled, "") Like "*-*-*"

or

If Nz(Me!Scheduled, "") Like "*-*-*" Then
Me!Scheduled.Locked = True
Else
Me!Scheduled.Locked = False
End If
 
Back
Top