After Update

  • Thread starter Thread starter Céline Brien
  • Start date Start date
C

Céline Brien

Hi !
Field NoMember named Member
Field Service (Yes or No) named S
After update of NoMember, if number >899 or <1 000, I would like the
Service field to be True.
I tried these codes, without the If, just to see it worked. It did'nt.
 
I'm not real clear on the names of the objects here, but try something like
this:

Private Sub Member_AfterUpdate()
If (Me.Member > 899) And (Me.Member) < 1000 Then
Me.S = True
Else
Me.S = False
End If
End Sub
 
I'm a bit confused here, Céline. If 'Member' is the name of the first field,
then what is 'NoMember'? Likewise if 'S' is the name of the second field,
then what is 'Service'?

I can not see any reason why the code you posted would fail, provided that
a) Member is an editable control on the form, b) S is a field in the form's
record source or a control bound to a field in the form's record source and
c) the field is of a data type capable of accepting the value -1, which a
Jet Yes/No field certainly can.

For example ...

I create a table in an MDB, with two fields, 'Member', a Long Integer, and
'S', a Yes/No field. (I'm assuming that 'Member' is a number because of your
reference to a number between 899 and 1000). I used the AutoForm wizard to
create a form bound to this table, with a text box named 'Member' bound to
the 'Member' field, and a check box named 'S' bound to the 'S' field. I add
the code you posted to the AfterUpdate event procedure of the text box
'Member'

Private Sub Member_AfterUpdate()

Me.S = -1

End Sub

As soon as I edit the contents of the text box 'Member' and press the Enter
or Tab keys, the check box is checked.

If you can identify what is different between this scenario and your
scenario, that will probably reveal where the problem lies.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Hi Brendan,
Thank you for your answer.
The name of my field is not the same as the name of the control.
S is the name of the control Service
Member is the name of the control NoMember.
I did that to have a narrow title for my column in the sub form. I
realize it is a bit confusing !
But after another try, you're right, it worked.
I used Allen codes for full solution and it worked fine.
-------------------------------------------------------
Private Sub Member_AfterUpdate()
If (Me.Member > 899) And (Me.Member) < 1000 Then
Me.S = True
Else
Me.S = False
End If
End Sub
 
Hi Allen,
Thank you for your answer.
Your codes work fine !
I took a note for the futur If Then Else End If.
Question :
Is
If (Me.Member > 899) And (Me.Member) < 1000 Then
the same as
If (Me.Member > 899) And (Me.Member < 1000) Then
or
If Me.Membre > 899 And Me.Membre < 1000 Then
??
Would you suggest to use parentheses just to make the codes more clear ?
Thanks again,
Céline

Allen Browne said:
I'm not real clear on the names of the objects here, but try something like
this:

Private Sub Member_AfterUpdate()
If (Me.Member > 899) And (Me.Member) < 1000 Then
Me.S = True
Else
Me.S = False
End If
End Sub
 
The parentheses are optional.

The clearest expression would be:
If (Me.Member > 899) And (Me.Member < 1000) Then
 
Back
Top