Functions and Subs

M

Max

Why does this work when placed directly behind the form as an "Expression",
but fails as a "Function"???? The point of failure is the response =
acDataErrContinue, which turns of access system messages.

I currently use this same piece of code several times in the DB, but thought
it would be better calling it as a function from within a module?????

Does it need to be specified as a public function or something, basicly
trying to reference same message several times?? Have search Microsoft and
other sites on the net but no help or luck so far.


----------------------------------------------------------------------------
----

Function getNotInList()

Dim strMsg As String
Dim strTitle As String
Dim intStyle As Integer

strMsg = "You Must Select an Option from the List Available!" &
vbCrLf & "Please See Admin Department for Additions to This Listing."
intStyle = vbOKOnly + vbExclamation
strTitle = "WinZues - Invalid Data Input"
MsgBox strMsg, intStyle, strTitle

response = acDataErrContinue 'Disables system default error
messages
' Response = acDataErrDisplay 'Enables system default error
messages

End Function


----------------------------------------------------------------------------
----

this is same code that sit on the "OnNotInList" property of form control -
this works but used too often


----------------------------------------------------------------------------
----


Private Sub StaffStatus_NotInList(newdata As String, response As Integer)

Dim strMsg As String, strTitle As String
Dim intStyle As Integer
strMsg = "You Must Select a Status from the List Available!" &
vbCrLf & "Please See Admin Department for Additions to This Listing."
intStyle = vbOKOnly + vbExclamation
strTitle = "WinZeus - Invalid Data Input"
MsgBox strMsg, intStyle, strTitle

response = acDataErrContinue 'Disables system default error
messages
' Response = acDataErrDisplay 'Enables system default error
messages

End Sub
 
M

Marshall Barton

Response is a By Ref argument of the NotInList event
procedure, it doesn't exist outside that procedure.

You can get what you want by having your function pass the
desired response value back to the NotInList procedure where
it can then be assigned to the Response argument. The code
might be structure along these lines:

Sub somecombo_NotInList(newdata, response)
. . .
Resonse = getNotInList()
. . .
End Sub

Function getNotInList()
. . .
getNotInList = acDataErrContinue 'tell caller what to do
. . .
End Function
 

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

Top