- Local time
- Today, 14:26
- Joined
- Feb 19, 2013
- Messages
- 16,606
I have many forms with the same code in the form error handler event, and often this is the only code in the form. I would like to remove it from the forms and set hasmodule to false and in the event properties, rather than having [EventProcedure] have =frm_errHandler(....) with frm_errHandler being a public function in a module.
I use this quite a lot for other functions, but this is the first time I am stumped on the parameters to pass.
I know I can call the module function from within the usual form error handler event and pick the parameters up from there, but this means I cannot set hasmodules to false. The problem is how to pass the parameters in the call (e.g. =frm_errHandler(dataerr) ) - they are clearly populated on the call, but How do I pick them up from the module or the form environment?
as an example, this cut down version enables a user to enter a calculation into a numeric field. e.g. (2*3)+4 - will evaluate to 10.
To put this into a module,
I need to know the value for dataerr and send the response back. The question is - where do I get it from? I've tried passing the form through as a parameter, but cannot find the dataerr value within the form object.
Any suggestions?
I use this quite a lot for other functions, but this is the first time I am stumped on the parameters to pass.
I know I can call the module function from within the usual form error handler event and pick the parameters up from there, but this means I cannot set hasmodules to false. The problem is how to pass the parameters in the call (e.g. =frm_errHandler(dataerr) ) - they are clearly populated on the call, but How do I pick them up from the module or the form environment?
as an example, this cut down version enables a user to enter a calculation into a numeric field. e.g. (2*3)+4 - will evaluate to 10.
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 0 ' there is no error - note this case option not really required, just shown for completeness
response=0
SendKeys "{ENTER}"
Case 2113 'there is text in numeric field
'see if it will evaluate to a number
On Error Resume Next
Screen.ActiveControl.Text = Eval(Nz(Screen.ActiveControl.Text, "0"))
Select Case Err.Number
Case 0 'no error, calculation has evaluated to a number
Response = 0
SendKeys "{ENTER}"
Case 2420, 2431, 2434, 2436, 2438, 2482 'unable to evaluate text in a numeric field to a number
MsgBox "Sorry - this entry does not evaluate to a number" & vbCrLf & "Please re-enter", vbOKOnly + vbExclamation, "Entry Error"
Response = 0 'so standard error message is not generated
Case Else
End Select
End Select
End Sub
Code:
Function frm_errHandler(frm as form??, dataerr as integer???, Response as Integer??)
...
code as above
...
end function
Any suggestions?