simplified AfterUpdate?

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.
 
J

jlute

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

checking for null 2
OnExit driving me crazy 3
BefreUpdate set to null error 2115 6
<= 0 11
Run-Time Error 2501 The OpenForm action was cancelled 1
type mismatch 3
DoCmd.GoToControl 10
SetFocus 8

Top