Using ComboBox Value to Update Text Boxes (1 Viewer)

rlreynolds217

Registered User.
Local time
Today, 13:24
Joined
Oct 4, 2012
Messages
11
Hello, I am trying to program a Risk Management Matrix. Once the user selects the risk from a combobox, then the probability and impact should be updated. After the probability and impact are updated (values pulled from the record associated with the combobox record), then the matrix should be updated. It is a 5x5 matrix that should be controlled by "if" statements (ex, if Probability = 3 and Impact = 4, then textbox P3_I4_matrix gets the combobox risk number).

I am having problems first updating the Probability and Impact, then secondly updating the matrix.

Here is the code to assign the P_I Matrix boxes:
Private Sub cboUpdateP_I_Click()
If Me.RiskMatrixP = 1 Then
If Me.RiskMatrixI = 1 Then
Me.P1_I1 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 2 Then
Me.P1_I2 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 3 Then
Me.P1_I3 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 4 Then
Me.P1_I4 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 5 Then
Me.P1_I5 = txtRiskforMatrix
End If
ElseIf Me.RiskMatrixP.Value = 2 Then
If Me.RiskMatrixI.Value = 1 Then
Me.P2_I1 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 2 Then
Me.P2_I2 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 3 Then
Me.P2_I3 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 4 Then
Me.P2_I4 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 5 Then
Me.P2_I5 = txtRiskforMatrix
End If
ElseIf Me.RiskMatrixP.Value = 3 Then
If Me.RiskMatrixI.Value = 1 Then
Me.P3_I1 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 2 Then
Me.P3_I2 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 3 Then
Me.P3_I3 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 4 Then
Me.P3_I4 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 5 Then
Me.P3_I5 = txtRiskforMatrix
End If
ElseIf Me.RiskMatrixP.Value = 4 Then
If Me.RiskMatrixI.Value = 1 Then
Me.P4_I1 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 2 Then
Me.P4_I2 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 3 Then
Me.P4_I3 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 4 Then
Me.P4_I4 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 5 Then
Me.P4_I5 = txtRiskforMatrix
End If

ElseIf Me.RiskMatrixP.Value = 5 Then
If Me.RiskMatrixI.Value = 1 Then
Me.P5_I1 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 2 Then
Me.P5_I2 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 3 Then
Me.P5_I3 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 4 Then
Me.P5_I4 = txtRiskforMatrix
ElseIf Me.RiskMatrixI.Value = 5 Then
Me.P5_I5 = txtRiskforMatrix
End If
End If

End Sub
 

pr2-eugin

Super Moderator
Local time
Today, 18:24
Joined
Nov 30, 2011
Messages
8,494
I am not sure if you will be happy with this, but your code can be reduced a lot more easier if you
(a) Chose Option Boxes instead of Combo Box, easier to choose and manipulate,
(b) Made the Values from the Combo (my choice Option group) the name of the control..

What I am saying is,
Step - 1 : Create a Probability Option Group with choices 1 to 5, call it probOptGroup
Step - 2 : Create another Option group (Impact) with choices 1 to 5, call it impOptGroup
Step - 3 : Set Default values for them both to be 1 and 1, In the after update of the groups call another common Sub,
Code:
Private Sub createOutput() 
    controlName As String
    controlName = "P" & Me.probOptGroup & "_I" & Me.impOptGroup
    Me.Controls(controlName) = [COLOR=Red]txtRiskforMatrix[/COLOR]
End Sub

Private Sub probOptGroup_AfterUpdate()
    Call createOutput
End Sub

Private Sub impOptGroup_AfterUpdate()
    Call createOutput
End Sub
I have not tested this, as I do not have Access on my computer, but it should work.. Try it out and give a shout..
 

Users who are viewing this thread

Top Bottom