In a sub-form : when entering a field, verify if another field is true, if so show a MsgBox + set fo

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

Céline Brien

Hi everybody,
I receive an error message when I select HreHPLeger.
Can you help ?
Many thanks,
Céline

Private Sub HrsHPLeger_Enter()
If ([ccPrive] = -1) Then

MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
Cancel = True
Me.HrsLeger.SetFocus

End If
End Sub
 
Celine,
Whenever you receive an error message... please include that in your
post.

At first glance, the Enter event doesn't have a Cancel, and you
shouldn't have to SetFocus when you have already entered the field.
Try this...

Private Sub HrsHPLeger_Enter()
If Me.[ccPrive] = -1 Then
MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
End If
End Sub

Every time you enter HrsHPLeger, and your ccPrive field = -1, the
MsgBox will fire.
Bon Chance!
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
Hello,
Thank you so much for your answer.
When the field ccPrive is true, the number of hours should be entered in the
field HrsLeger and not in the field HrsHPLeger.
So I would like to cancel the selection of the HrsHPLeger field and bring
the user to the field.HrsLeger.
To simplify, I used your code and I still receive the following error
message :
--------------------------------------------------------
L'expression Sur entrée entrée comme paramètre de la propriété de type
événement est à l'origine d'une erreur. Utilisation incorrecte de la
propriété.
* Le résultat de l'expression n'est pas le nom d'une macro, le nom d'une
fonction définie par l'utilisateur ou [Event Procedure].
* Une erreur a peut-être été commise lors de l'évaluation d'une fonction,
d'un événement ou d'une macro.
--------------------------------------------------------
Can you help ?
Céline


Al Campagna said:
Celine,
Whenever you receive an error message... please include that in your
post.

At first glance, the Enter event doesn't have a Cancel, and you
shouldn't have to SetFocus when you have already entered the field.
Try this...

Private Sub HrsHPLeger_Enter()
If Me.[ccPrive] = -1 Then
MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
End If
End Sub

Every time you enter HrsHPLeger, and your ccPrive field = -1, the
MsgBox will fire.
Bon Chance!
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

Céline Brien said:
Hi everybody,
I receive an error message when I select HreHPLeger.
Can you help ?
Many thanks,
Céline

Private Sub HrsHPLeger_Enter()
If ([ccPrive] = -1) Then

MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
Cancel = True
Me.HrsLeger.SetFocus

End If
End Sub
 
Celine,
Use the AfterUpdate event of ccPrive...
Again, *use your own control names* in the sample code...

Private Sub ccPrive_AfterUpdate()
If ccPrive = True Then
HrsLeger = [NoOfHours]
Docmd.GoToControl "HrsLeger"
End If
End Sub

If the user selects True for ccPrive, HrsLeger will receive the value of
NoOfHours, and the user will be sent to the HrsLeger control.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


Céline Brien said:
Hello,
Thank you so much for your answer.
When the field ccPrive is true, the number of hours should be entered in
the field HrsLeger and not in the field HrsHPLeger.
So I would like to cancel the selection of the HrsHPLeger field and bring
the user to the field.HrsLeger.
To simplify, I used your code and I still receive the following error
message :
--------------------------------------------------------
L'expression Sur entrée entrée comme paramètre de la propriété de type
événement est à l'origine d'une erreur. Utilisation incorrecte de la
propriété.
* Le résultat de l'expression n'est pas le nom d'une macro, le nom d'une
fonction définie par l'utilisateur ou [Event Procedure].
* Une erreur a peut-être été commise lors de l'évaluation d'une fonction,
d'un événement ou d'une macro.
--------------------------------------------------------
Can you help ?
Céline


Al Campagna said:
Celine,
Whenever you receive an error message... please include that in your
post.

At first glance, the Enter event doesn't have a Cancel, and you
shouldn't have to SetFocus when you have already entered the field.
Try this...

Private Sub HrsHPLeger_Enter()
If Me.[ccPrive] = -1 Then
MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
End If
End Sub

Every time you enter HrsHPLeger, and your ccPrive field = -1, the
MsgBox will fire.
Bon Chance!
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your
life."

Céline Brien said:
Hi everybody,
I receive an error message when I select HreHPLeger.
Can you help ?
Many thanks,
Céline

Private Sub HrsHPLeger_Enter()
If ([ccPrive] = -1) Then

MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
Cancel = True
Me.HrsLeger.SetFocus

End If
End Sub
 
Hello,
Thank you for your answer.
I am on the road today.
I will try your solution tomorrow and give you a feedback.
Many thanks again !
Céline

Al Campagna said:
Celine,
Use the AfterUpdate event of ccPrive...
Again, *use your own control names* in the sample code...

Private Sub ccPrive_AfterUpdate()
If ccPrive = True Then
HrsLeger = [NoOfHours]
Docmd.GoToControl "HrsLeger"
End If
End Sub

If the user selects True for ccPrive, HrsLeger will receive the value
of NoOfHours, and the user will be sent to the HrsLeger control.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


Céline Brien said:
Hello,
Thank you so much for your answer.
When the field ccPrive is true, the number of hours should be entered in
the field HrsLeger and not in the field HrsHPLeger.
So I would like to cancel the selection of the HrsHPLeger field and bring
the user to the field.HrsLeger.
To simplify, I used your code and I still receive the following error
message :
--------------------------------------------------------
L'expression Sur entrée entrée comme paramètre de la propriété de type
événement est à l'origine d'une erreur. Utilisation incorrecte de la
propriété.
* Le résultat de l'expression n'est pas le nom d'une macro, le nom d'une
fonction définie par l'utilisateur ou [Event Procedure].
* Une erreur a peut-être été commise lors de l'évaluation d'une fonction,
d'un événement ou d'une macro.
--------------------------------------------------------
Can you help ?
Céline


Al Campagna said:
Celine,
Whenever you receive an error message... please include that in your
post.

At first glance, the Enter event doesn't have a Cancel, and you
shouldn't have to SetFocus when you have already entered the field.
Try this...

Private Sub HrsHPLeger_Enter()
If Me.[ccPrive] = -1 Then
MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
End If
End Sub

Every time you enter HrsHPLeger, and your ccPrive field = -1, the
MsgBox will fire.
Bon Chance!
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your
life."

Hi everybody,
I receive an error message when I select HreHPLeger.
Can you help ?
Many thanks,
Céline

Private Sub HrsHPLeger_Enter()
If ([ccPrive] = -1) Then

MsgBox "Membre privé", vbOKOnly, "Saisir les heures dans le champ
HrsLeger"
Cancel = True
Me.HrsLeger.SetFocus

End If
End Sub
 
Back
Top