M
Matt Lockamy
I'm using the BeforeUpdate event to validate information based on a
combination of fields. There is a REASON_CODE field where the user specifies
the reason he is returning an item, an ITEM_ACTUAL where the user specifies
which item he was actually sent, and a quantity field where the user
specifies the QTY he is returning.
If the user specifies the code for Wrong Item, I want to force him to enter
the item ID for the item he was actually sent. I couldn't figure out which
event to use on that field, so I used the BeforeUpdate event on the QTY field
(which is the last field on the subform). That way, if a user tries to enter
a quantity and the code is "WI", then he will be forced to enter an item in
the ITEM_ACTUAL field.
Here is my code:
Private Sub QTY_BeforeUpdate(Cancel As Integer)
Dim strCode As String
Dim strItemSent As String
strCode = ITEM_REASON_CODE.Value
strItemSent = Nz(ITEM_ACTUAL.Value)
If strCode = "WI" And strItemSent = "" Then
Cancel = True
MsgBox "If Reason Code WI is selected, you must specify which Item was
actually sent.", vbOKOnly
Me.QTY.Undo
DoCmd.GoToControl ITEM_ACTUAL.Name
End If
End Sub
The problem is that when I try to use the GoToControl method it tells me I
have to save the record, which is exactly what I don't want to do. In the
form I can just tab to another field without updating the record, why can't I
do it in VBA? I think it would be helpful to change the focus to the field
where the problem actually is.
Your help is very much appreciated.
combination of fields. There is a REASON_CODE field where the user specifies
the reason he is returning an item, an ITEM_ACTUAL where the user specifies
which item he was actually sent, and a quantity field where the user
specifies the QTY he is returning.
If the user specifies the code for Wrong Item, I want to force him to enter
the item ID for the item he was actually sent. I couldn't figure out which
event to use on that field, so I used the BeforeUpdate event on the QTY field
(which is the last field on the subform). That way, if a user tries to enter
a quantity and the code is "WI", then he will be forced to enter an item in
the ITEM_ACTUAL field.
Here is my code:
Private Sub QTY_BeforeUpdate(Cancel As Integer)
Dim strCode As String
Dim strItemSent As String
strCode = ITEM_REASON_CODE.Value
strItemSent = Nz(ITEM_ACTUAL.Value)
If strCode = "WI" And strItemSent = "" Then
Cancel = True
MsgBox "If Reason Code WI is selected, you must specify which Item was
actually sent.", vbOKOnly
Me.QTY.Undo
DoCmd.GoToControl ITEM_ACTUAL.Name
End If
End Sub
The problem is that when I try to use the GoToControl method it tells me I
have to save the record, which is exactly what I don't want to do. In the
form I can just tab to another field without updating the record, why can't I
do it in VBA? I think it would be helpful to change the focus to the field
where the problem actually is.
Your help is very much appreciated.