I'm attempting to put in some VBA code to simplify data entry, by updating controls on a subform based on prior entries. In essence, as the user enters values going from left to right, these values can in some cases, modify values further along the list accordingly. However, my problem seems to be that some of the controls aren't updating as the code says, and the savecommand isn't executing either. Though this may be because I misunderstand the sequence of events in the Afterupdate of the control. I'm wanting the saverecord command to execute because this cascades through subsequent cells and performs calculations based on the changes occuring here.
The width entry for some reason will not update on the form no matter which case I select. I have checked my form and the control name is indeed Width. The material_type, and the height will update fine, but never the width, and the saverecord command isn't being called at all, though this may be because once a case is met the subroutine ends and the saverecord is never reached, is that how it works?
I would also appreciate any constructive criticism on the formatting of the above. To me is seems that I'm missing something obvious in terms of a method of simplyfying this code.
Kyle
Code:
Private Sub Cost_Code_AfterUpdate()
Select Case [Cost Code]
Case Is = 421
Me.Material_Type = "Waste"
Me.Height = 15
Me.Width = 15
Case Is = 422
If (Parent.[Zone] = "US" Or Parent.[Zone] = "UN" Or Parent.[Zone] = "UE") Then
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 20
Else
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 25
End If
Case Is = 423
If (Parent.[Zone] = "US" Or Parent.[Zone] = "UN" Or Parent.[Zone] = "UE") Then
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 20
Else
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 25
End If
Case Is = 441
If (Parent.[Zone] = "SM") Then
Me.Material_Type = "Ore"
Me.Height = 17
Me.Width = 16
Else
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 15
End If
Case Is = 442
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 15
Case Else
Me.Material_Type = "Ore"
Me.Height = 15
Me.Width = 15
End Select
DoCmd.RunCommand acCmdSaveRecord
End Sub
The width entry for some reason will not update on the form no matter which case I select. I have checked my form and the control name is indeed Width. The material_type, and the height will update fine, but never the width, and the saverecord command isn't being called at all, though this may be because once a case is met the subroutine ends and the saverecord is never reached, is that how it works?
I would also appreciate any constructive criticism on the formatting of the above. To me is seems that I'm missing something obvious in terms of a method of simplyfying this code.
Kyle