Text box control source

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

Guest

On my form, I have an unbound text box [txtpercentatSite]. I also have
several option buttons. When the user selects option button 'Site' (option
1), I want [txtpercentatSite] to autofill "100%". But if the user selects
options button 'Both' (option 3), I want the user to be able to enter any
number in [txtpercentatSite]. I have tried "=IIf([fraSiteOrMOSO]=1,1)" in
Control Source, but the field is then not editable.
Note - [txtpercentatSite] already has an After Update event procedure:
Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
I think you need an afterUpdate event for the option group - something like
this. I didn't know whether you wanted to lock the field if option 1 is
selected but in case you do, here is how. I also wasn't clear on what you
wanted for option 2 but you can probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub
 
Sandra,

Many thanks, that's great. It did exactly what I asked, but you are also
right that I didn't specify option 2. I wonder if you could add the code for
that:

Option 2 is 'MOSO'. If this is selected, I would like [txtpercentatMOSO] to
be autofilled with "100%" (and locked), and [txtpercentatSite] to return to
"0%", also locked.

John

Sandra Daigle said:
I think you need an afterUpdate event for the option group - something like
this. I didn't know whether you wanted to lock the field if option 1 is
selected but in case you do, here is how. I also wasn't clear on what you
wanted for option 2 but you can probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

On my form, I have an unbound text box [txtpercentatSite]. I also have
several option buttons. When the user selects option button 'Site'
(option 1), I want [txtpercentatSite] to autofill "100%". But if the
user selects options button 'Both' (option 3), I want the user to be
able to enter any number in [txtpercentatSite]. I have tried
"=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the field is then
not editable.
Note - [txtpercentatSite] already has an After Update event procedure:
Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Sandra,

Apologies for jumping in before you have replied, but I think I may have got
it. Is the code below correct? It seems to work. So, what code could I write
to prevent the users entering percentages in the 2 fields that exceed 100% in
total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

JohnP said:
Sandra,

Many thanks, that's great. It did exactly what I asked, but you are also
right that I didn't specify option 2. I wonder if you could add the code for
that:

Option 2 is 'MOSO'. If this is selected, I would like [txtpercentatMOSO] to
be autofilled with "100%" (and locked), and [txtpercentatSite] to return to
"0%", also locked.

John

Sandra Daigle said:
I think you need an afterUpdate event for the option group - something like
this. I didn't know whether you wanted to lock the field if option 1 is
selected but in case you do, here is how. I also wasn't clear on what you
wanted for option 2 but you can probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

On my form, I have an unbound text box [txtpercentatSite]. I also have
several option buttons. When the user selects option button 'Site'
(option 1), I want [txtpercentatSite] to autofill "100%". But if the
user selects options button 'Both' (option 3), I want the user to be
able to enter any number in [txtpercentatSite]. I have tried
"=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the field is then
not editable.
Note - [txtpercentatSite] already has an After Update event procedure:
Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Here you go - it's pretty basic as you can see below - but now you probably
also want to unlock me.txtpercentatMOSO somewhere - otherwise it will remain
locked after the first time someone selects option 2.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
case 2
me.txtpercentatMOSO=100
me.txtpercentatMOSO.locked=true
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
'Maybe add it here?
' me.txtpercentatMOSO.locked=False
Me.txtpercentatSite.SetFocus
End Select
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sandra,

Many thanks, that's great. It did exactly what I asked, but you are
also right that I didn't specify option 2. I wonder if you could add
the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

Sandra Daigle said:
I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

On my form, I have an unbound text box [txtpercentatSite]. I also
have several option buttons. When the user selects option button
'Site' (option 1), I want [txtpercentatSite] to autofill "100%".
But if the user selects options button 'Both' (option 3), I want
the user to be able to enter any number in [txtpercentatSite]. I
have tried "=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the
field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Look at the BeforeUpdate event of the form. Something like this will work:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.txtpercentatMOSO + Me.txtpercentatSite) > 100 Then
MsgBox "The total percent can not exceed 100. " _
& "Please correct before continuing.", _
vbExclamation + vbOKOnly
Cancel = True
End If
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sandra,

Apologies for jumping in before you have replied, but I think I may
have got it. Is the code below correct? It seems to work. So, what
code could I write to prevent the users entering percentages in the 2
fields that exceed 100% in total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

JohnP said:
Sandra,

Many thanks, that's great. It did exactly what I asked, but you are
also right that I didn't specify option 2. I wonder if you could add
the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

Sandra Daigle said:
I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
On my form, I have an unbound text box [txtpercentatSite]. I also
have several option buttons. When the user selects option button
'Site' (option 1), I want [txtpercentatSite] to autofill "100%".
But if the user selects options button 'Both' (option 3), I want
the user to be able to enter any number in [txtpercentatSite]. I
have tried "=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the
field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Thanks again, but that doesn't work in the BeforeUpdate event of my form. I
suspect that this is because my form is not bound to a table - I have a
button to write to the table.

Would it work in the AfterUpdate event of the txtpercentatMOSO and
txtpercentatSite fields?

Sandra Daigle said:
Look at the BeforeUpdate event of the form. Something like this will work:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.txtpercentatMOSO + Me.txtpercentatSite) > 100 Then
MsgBox "The total percent can not exceed 100. " _
& "Please correct before continuing.", _
vbExclamation + vbOKOnly
Cancel = True
End If
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sandra,

Apologies for jumping in before you have replied, but I think I may
have got it. Is the code below correct? It seems to work. So, what
code could I write to prevent the users entering percentages in the 2
fields that exceed 100% in total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

JohnP said:
Sandra,

Many thanks, that's great. It did exactly what I asked, but you are
also right that I didn't specify option 2. I wonder if you could add
the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

:

I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
On my form, I have an unbound text box [txtpercentatSite]. I also
have several option buttons. When the user selects option button
'Site' (option 1), I want [txtpercentatSite] to autofill "100%".
But if the user selects options button 'Both' (option 3), I want
the user to be able to enter any number in [txtpercentatSite]. I
have tried "=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the
field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
You would need to put the code in the BeforeUpate events of both fields to
catch the potential error. The Cancel=True statement will still work - it
will cause the cursor to remain in the control being updated until the error
is corrected.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Thanks again, but that doesn't work in the BeforeUpdate event of my
form. I suspect that this is because my form is not bound to a table
- I have a button to write to the table.

Would it work in the AfterUpdate event of the txtpercentatMOSO and
txtpercentatSite fields?

Sandra Daigle said:
Look at the BeforeUpdate event of the form. Something like this will
work:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.txtpercentatMOSO + Me.txtpercentatSite) > 100 Then
MsgBox "The total percent can not exceed 100. " _
& "Please correct before continuing.", _
vbExclamation + vbOKOnly
Cancel = True
End If
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sandra,

Apologies for jumping in before you have replied, but I think I may
have got it. Is the code below correct? It seems to work. So, what
code could I write to prevent the users entering percentages in the
2 fields that exceed 100% in total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

:

Sandra,

Many thanks, that's great. It did exactly what I asked, but you are
also right that I didn't specify option 2. I wonder if you could
add the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

:

I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
On my form, I have an unbound text box [txtpercentatSite]. I also
have several option buttons. When the user selects option button
'Site' (option 1), I want [txtpercentatSite] to autofill "100%".
But if the user selects options button 'Both' (option 3), I want
the user to be able to enter any number in [txtpercentatSite]. I
have tried "=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the
field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Great. I shall add this code tomorrow, but with all your help I've taken a
big leap forwards today.

Have a good day.

John

Sandra Daigle said:
You would need to put the code in the BeforeUpate events of both fields to
catch the potential error. The Cancel=True statement will still work - it
will cause the cursor to remain in the control being updated until the error
is corrected.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Thanks again, but that doesn't work in the BeforeUpdate event of my
form. I suspect that this is because my form is not bound to a table
- I have a button to write to the table.

Would it work in the AfterUpdate event of the txtpercentatMOSO and
txtpercentatSite fields?

Sandra Daigle said:
Look at the BeforeUpdate event of the form. Something like this will
work:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.txtpercentatMOSO + Me.txtpercentatSite) > 100 Then
MsgBox "The total percent can not exceed 100. " _
& "Please correct before continuing.", _
vbExclamation + vbOKOnly
Cancel = True
End If
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
Sandra,

Apologies for jumping in before you have replied, but I think I may
have got it. Is the code below correct? It seems to work. So, what
code could I write to prevent the users entering percentages in the
2 fields that exceed 100% in total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

:

Sandra,

Many thanks, that's great. It did exactly what I asked, but you are
also right that I didn't specify option 2. I wonder if you could
add the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

:

I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
On my form, I have an unbound text box [txtpercentatSite]. I also
have several option buttons. When the user selects option button
'Site' (option 1), I want [txtpercentatSite] to autofill "100%".
But if the user selects options button 'Both' (option 3), I want
the user to be able to enter any number in [txtpercentatSite]. I
have tried "=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the
field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Sandra should double check this, but the equivalent to the
BeforeUpdate event in an unbound form is in your save
button's Click event (before the code that does the actual
save operation and replace the Cancel = True with Exit Sub).
--
Marsh
MVP [MS Access]

Thanks again, but that doesn't work in the BeforeUpdate event of my form. I
suspect that this is because my form is not bound to a table - I have a
button to write to the table.

Would it work in the AfterUpdate event of the txtpercentatMOSO and
txtpercentatSite fields?

Sandra Daigle said:
Look at the BeforeUpdate event of the form. Something like this will work:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.txtpercentatMOSO + Me.txtpercentatSite) > 100 Then
MsgBox "The total percent can not exceed 100. " _
& "Please correct before continuing.", _
vbExclamation + vbOKOnly
Cancel = True
End If
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Sandra,

Apologies for jumping in before you have replied, but I think I may
have got it. Is the code below correct? It seems to work. So, what
code could I write to prevent the users entering percentages in the 2
fields that exceed 100% in total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

:

Sandra,

Many thanks, that's great. It did exactly what I asked, but you are
also right that I didn't specify option 2. I wonder if you could add
the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

:

I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
On my form, I have an unbound text box [txtpercentatSite]. I also
have several option buttons. When the user selects option button
'Site' (option 1), I want [txtpercentatSite] to autofill "100%".
But if the user selects options button 'Both' (option 3), I want
the user to be able to enter any number in [txtpercentatSite]. I
have tried "=IIf([fraSiteOrMOSO]=1,1)" in Control Source, but the
field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Yeah, that would work and would probably be less annoying to the user. I got
fixated on the Update events! Thanks Marsh!

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Marshall said:
Sandra should double check this, but the equivalent to the
BeforeUpdate event in an unbound form is in your save
button's Click event (before the code that does the actual
save operation and replace the Cancel = True with Exit Sub).
Thanks again, but that doesn't work in the BeforeUpdate event of my
form. I suspect that this is because my form is not bound to a table
- I have a button to write to the table.

Would it work in the AfterUpdate event of the txtpercentatMOSO and
txtpercentatSite fields?

Sandra Daigle said:
Look at the BeforeUpdate event of the form. Something like this
will work:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If (Me.txtpercentatMOSO + Me.txtpercentatSite) > 100 Then
MsgBox "The total percent can not exceed 100. " _
& "Please correct before continuing.", _
vbExclamation + vbOKOnly
Cancel = True
End If
End Sub


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
Sandra,

Apologies for jumping in before you have replied, but I think I may
have got it. Is the code below correct? It seems to work. So, what
code could I write to prevent the users entering percentages in
the 2 fields that exceed 100% in total?

Private Sub fraSiteOrMOSO_AfterUpdate()
Select Case Me.fraSiteOrMOSO
Case 1
Me.txtpercentatSite = 1
Me.txtpercentatSite.Locked = True
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = True
Case 2
Me.txtpercentatMOSO = 1
Me.txtpercentatMOSO.Locked = True
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite = 0
Me.txtpercentatSite.Locked = False
Me.txtpercentatMOSO = 0
Me.txtpercentatMOSO.Locked = False
End Select
End Sub

:

Sandra,

Many thanks, that's great. It did exactly what I asked, but you
are also right that I didn't specify option 2. I wonder if you
could add the code for that:

Option 2 is 'MOSO'. If this is selected, I would like
[txtpercentatMOSO] to be autofilled with "100%" (and locked), and
[txtpercentatSite] to return to "0%", also locked.

John

:

I think you need an afterUpdate event for the option group -
something like this. I didn't know whether you wanted to lock the
field if option 1 is selected but in case you do, here is how. I
also wasn't clear on what you wanted for option 2 but you can
probably add it.

Private Sub Frame4_AfterUpdate()
Select Case Me.Frame4
Case 1
Me.txtpercentatSite = 100
Me.txtpercentatSite.Locked = True
Case 3
Me.txtpercentatSite.Locked = False
Me.txtpercentatSite.SetFocus
End Select
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


JohnP wrote:
On my form, I have an unbound text box [txtpercentatSite]. I
also have several option buttons. When the user selects option
button 'Site' (option 1), I want [txtpercentatSite] to autofill
"100%". But if the user selects options button 'Both' (option
3), I want the user to be able to enter any number in
[txtpercentatSite]. I have tried "=IIf([fraSiteOrMOSO]=1,1)" in
Control Source, but the field is then not editable.
Note - [txtpercentatSite] already has an After Update event
procedure: Private Sub txtpercentatSite_AfterUpdate()
Me!txtpercentatSite = (Me!txtpercentatSite / 100)
End Sub
 
Back
Top