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

Bob Quintal

(e-mail address removed) wrote in
56g2000hsm.googlegroups.com
:
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.

In the form, create a new sub-procedure, named for example
CheckUOMs, that handles the entrire group, and call that procedure
from each of the six event procedures

Private Sub IDLengthUOM_AfterUpdate()
CheckUOMs "IDL"
End Sub

Private Sub CheckUOMs(myTextBox as string)
' code to do everything goes here.
Select Case "IDL"
' code to do IDW and IDH goes here.
if Me!IDLengthUOM <> Me!IDWiddthUOM OR _
Me!IDLengthUOM <> Me!IDHeightUOM Then
' code to set IDW and IDH goes here.
end if
Select Case "IDW"
' code to set IDL and IDH goes here.
Select Case "IDH"
....etc,
end select

End Sub.
 
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


Top