AlexN
Registered User.
- Local time
- Today, 03:26
- Joined
- Nov 10, 2014
- Messages
- 302
Hi everyone,
I use the following code behind the BeforeUpdate event of a control, to validate input.
There are two different forms that use that control and this code behind the BeforeUpdate event.
It works on one but not on the other, allowing to input anything in the control with checking and without bringing up any msgbox.
Searching what's the problem in the immediate window, brings up a message saying "External Name not defined'. I couldn't find the meaning of this and it seems I can't find any solution.
Anyone with a good idea?
Thanks!!!
I use the following code behind the BeforeUpdate event of a control, to validate input.
Code:
Private Sub StockPrice_BeforeUpdate(Cancel As Integer)
'strings used for the MsgBox
Dim strTitle As String
Dim strMsg1 As String
Dim strMsg2 As String
Dim strMsg3 As String
Dim strMsg4 As String
Dim strMsg As String
'buttons to display on the MsgBox
Dim intMsgDialog As Integer
'result returned from the MsgBox
Dim intResult As Integer
'Comparison object
Dim LPrice As Variant
Dim HPrice As Variant
LPrice = DLookup("[Low]", "SubQryActiveStockPrices", "[PStockID]=" & [StockID] & " AND [TradeDate]=#" & Me.Parent!TabletDate & "#")
HPrice = DLookup("[High]", "SubQryActiveStockPrices", "[PStockID]=" & [StockID] & " AND [TradeDate]=#" & Me.Parent!TabletDate & "#")
If Me.StockPrice > HPrice Or Me.StockPrice < LPrice Then
' Display a message box asking for retry with the proper value
strTitle = "Price Check"
intMsgDialog = vbOKOnly + vbExclamation + vbDefaultButton1
strMsg1 = "Price not reached!" & " "
strMsg2 = "Retry using a price between " & " "
strMsg3 = LPrice & " and " & " "
strMsg4 = HPrice
strMsg = strMsg1 + strMsg2 + strMsg3 + strMsg4
intResult = MsgBox(strMsg, intMsgDialog, strTitle)
If intResult = vbOK Then
Cancel = True
Me.StockPrice.Undo
End If
End If
End Sub
There are two different forms that use that control and this code behind the BeforeUpdate event.
It works on one but not on the other, allowing to input anything in the control with checking and without bringing up any msgbox.
Searching what's the problem in the immediate window, brings up a message saying "External Name not defined'. I couldn't find the meaning of this and it seems I can't find any solution.
Anyone with a good idea?
Thanks!!!