Change value in a control based upon another value

  • Thread starter Thread starter ken a
  • Start date Start date
K

ken a

I want to change the value in a control based upon the
value entered in another. I have written a macro to do
this on exit of the first control.
Problem is that the value in the second control i.e. the
one I want to change does in fact update , but does not
clear the previous value on screen. So if the previous
value was "No" and after changing the value to "Yes" it
becomes "Nos". I need therefore to clear the value first
and then paint the new value. If I go to the next record
and then return, the correct values are there.
I also want the second control to be enabled or not based
upon the value entered in the first control.
Any help would be appreciated.
 
I want to change the value in a control based upon the
value entered in another. I have written a macro to do
this on exit of the first control.
Problem is that the value in the second control i.e. the
one I want to change does in fact update , but does not
clear the previous value on screen. So if the previous
value was "No" and after changing the value to "Yes" it
becomes "Nos". I need therefore to clear the value first
and then paint the new value. If I go to the next record
and then return, the correct values are there.
I also want the second control to be enabled or not based
upon the value entered in the first control.
Any help would be appreciated.

Please post your code.

I'd use the AfterUpdate event of the first control rather than Exit
(the Exit event fires even if the user just tabs through without doing
anything); like

Private Sub FirstControl_AfterUpdate()
<determine the desired value>
If <whatever> Then
Me!SecondControl = "Yes"
Else
Me!SecondControl = "No"
End If

John W. Vinson[MVP]
 
Thanks for the reply. I have used AfterUpdate event as
suggested and it works ok, but still with the same
problem .

The code for the macro I used has been converted to a
function.
The code is

Function Risk1()
On Error GoTo Risk1_Err

With CodeContextObject
' If the first control is "Yes"
If (Forms![SOA Tabs 2]!S3_Risk_Only





= "Yes" ) Then

Forms![SOA Tabs 2]!S3_Anex_Priority





= "Yes"
End If
' If the first control is "No"
If (Forms![SOA Tabs 2]!S3_Risk_Only





= "No" ) Then

Forms![SOA Tabs 2]!S3_Anex_Priority





= "No"
End If
' Not sure whether this turns off the second
control.
' It doesn't appear to do anything.
If (.S3_Anex_Priority) Then

DoCmd.Echo True, ""
End If
End With


Risk1_Exit:
Exit Function

Risk1_Err:
MsgBox Error$
Resume Risk1_Exit

End Function
 
Back
Top