procedure declaration does not match

L

Loni - RWT

I copied the following code to handle "Not In List" data from another form
and changed the names and questions for this form. After doing so, when I
try to open the form I get this error message:

"The expression On Open you entered as the event property setting produced
the following error: Procedure declaration does not match description of
event or proceedure having the same name."

Here is the code:
Private Sub VendorID_BeforeUpdate(NewData As String, Response As Integer)
Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Is this a new vendor?"

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmVendor", _
datamode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
'ensure vendor has been added
If Not IsNull(DLookup("VendorID", "tblVendors", "VendorID = """ & _
NewData & """")) Then
Response = acDataErrAdded

Else
strMessage = NewData & " was not added to Vendors table."
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
End Sub

What is causing this error?
Thanks!
 
B

Bob Quintal

=?Utf-8?B?TG9uaSAtIFJXVA==?= <[email protected]>
wrote in
I copied the following code to handle "Not In List" data from
another form and changed the names and questions for this
form. After doing so, when I try to open the form I get this
error message:

"The expression On Open you entered as the event property
setting produced the following error: Procedure declaration
does not match description of event or proceedure having the
same name."
The code came from a combobox notinlist event. You are trying to
use it in a text,combo,orlistbox beforeupdate event.

The beforeUpdateEvent does not know what to do with the newdata
and response parameters.

Move the code from the beforeupdate event to the NotInList
event.


Here is the code:
Private Sub VendorID_BeforeUpdate(NewData As String, Response
As Integer)
Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Is this a new vendor?"

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmVendor", _
datamode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
'ensure vendor has been added
If Not IsNull(DLookup("VendorID", "tblVendors",
"VendorID = """ & _
NewData & """")) Then
Response = acDataErrAdded

Else
strMessage = NewData & " was not added to Vendors
table." MsgBox strMessage, vbInformation,
"Warning" Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
End Sub

What is causing this error?
Thanks!
 
U

UpRider

Loni, the event procedures have strict agruments that you must not change.
For example, your VendorID_BeforeUpdate has the arguments (NewData As
String, Response As Integer)
The required agrument is (Cancel As Integer). Maybe. Read on.
Now, if this sub is not an event procedure for your VendorID control (it is
not attached to the after_updated event event of that control), it is a
confusing name and should be changed to something like 'Private Sub
VendorID_PreUpdate(NewData As String, Response As Integer)'. Since it is
currently named in a way that Access would automatically name one of its
procedures, Access is just straining to attach that code to the after update
event of the VendorID control. When it does, you get your aforementioned
error.
So, where are we? The first place I would look is at frmVendor's code
module. You may find that the 'on open' event of that form is attached a
user named sub, not the Access created stub. That user created sub will
have incorrect arguments.

The required arguments for a form's open event is simply (). (no arguments)

To get the proper arguments is simple. On the form, select the control. Then
on the property sheet (F4 if you don'st see it), choose the event that you
want to code. In the drop down, choose 'event procedure', then click on the
.... next to it. The VB code window will open with the cursor placed in the
middle of the properly formed code.

Onward. If these subs are actually what you want, you can remove the errors
by removing the attachment between the event and the procedure. You do this
by blanking out the words "Event Procedure" in the control's property sheet
for that event.
Then to keep Access from reattaching the procedure (because of the name),
change the name of the subs slightly.
After changing the names, recompile and you will find all the occurances of
code calling those subs. Change the name of the callers to match the new
name.

This explanation is more difficult than fixing it, but the concepts are not
hard to understand once you grasp the method that Access uses to
automatically name it's event procedure subs.

HTH, UpRider
 

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