simplified AfterUpdate?

  • Thread starter Thread starter jlute
  • Start date Start date
J

jlute

I have a subform with 2 "groups" of controls:
IDLengthUOM
IDWidthUOM
IDHeightUOM

ODLengthUOM
ODWidthUOM
ODHeightUOM

Each control in each group is for storing a UOM value for:
IDLength
IDWidth
IDHeight

ODLength
ODWidth
ODHeight

Each UOM group must have the same value (either "in." or "mm"). I
suppose that I could've designated a single UOM control for each
group:
IDLength
IDWidth
IDHeight
IDUOM

ODLength
ODWidth
ODHeight
ODUOM

However, this would "violate" my design consistency and create other
problems. So in order to maintain design consistency AND assure that
each UOM group has the same value I developed this event:

Private Sub IDLengthUOM_AfterUpdate()
If (Me!IDLengthUOM = "in.") Then
Beep
If MsgBox("ID LxWxD UOM's must be the same!" & vbCrLf & _
"Click OK to set the WxD UOM's to in.", vbOKOnly + _
vbQuestion) = vbOK Then
Me!IDWidthUOM = "in."
Me!IDHeightUOM = "in."
DoCmd.GoToControl "IDWidth"
End If
ElseIf (Me!IDLengthUOM = "mm") Then
Beep
If MsgBox("ID LxWxD UOM's must be the same!" & vbCrLf & _
"Click OK to set the WxD UOM's to mm", vbOKOnly + _
vbQuestion) = vbOK Then
Me!IDWidthUOM = "mm"
Me!IDHeightUOM = "mm"
DoCmd.GoToControl "IDWidth"
End If
If (Me!IDLengthUOM = "in.") Then
If (Me!IDWidthUOM) = "mm" Then
Beep
If MsgBox("ID LxWxD UOM's must be the same!" & vbCrLf & _
"Click OK to set the WxD UOM's to in.", vbOKOnly + _
vbQuestion) = vbOK Then
Me!IDWidthUOM = "in."
Me!IDHeightUOM = "in."
DoCmd.GoToControl "IDWidth"
End If
ElseIf (Me!IDLengthUOM = "mm") Then
If (Me!IDWidthUOM) = "in." Then
Beep
If MsgBox("ID LxWxD UOM's must be the same!" & vbCrLf & _
"Click OK to set the WxD UOM's to mm", vbOKOnly + _
vbQuestion) = vbOK Then
Me!IDWidthUOM = "mm"
Me!IDHeightUOM = "mm"
DoCmd.GoToControl "IDWidth"
End If
ElseIf (Me!IDLengthUOM = "in.") Then
If (Me!IDHeightUOM) = "mm" Then
Beep
If MsgBox("ID LxWxD UOM's must be the same!" & vbCrLf & _
"Click OK to set the WxD UOM's to in.", vbOKOnly + _
vbQuestion) = vbOK Then
Me!IDWidthUOM = "in."
Me!IDHeightUOM = "in."
DoCmd.GoToControl "IDWidth"
End If
ElseIf (Me!IDLengthUOM = "mm") Then
If (Me!IDHeightUOM) = "in." Then
Beep
If MsgBox("ID LxWxD UOM's must be the same!" & vbCrLf & _
"Click OK to set the WxD UOM's to mm", vbOKOnly + _
vbQuestion) = vbOK Then
Me!IDWidthUOM = "mm"
Me!IDHeightUOM = "mm"
DoCmd.GoToControl "IDWidth"
End If
End If
End If
End If
End If
End If
End If
End Sub

Of course, similar events have been written for each of the 6 UOM
controls. This works fine however I'm curious if there's a more
simplified way. I suppose this is an exploratory exercise.
 
Thanks, Bob! I really didn't expect anyone to respond but I'm glad you
did!

That's an interesting approach. I may just try to modify to that. I'm
definitely saving this because I bet it'll come up again in my near
future.
 
Back
Top