Member already exists (1 Viewer)

Randomblink

The Irreverent Reverend
Local time
Today, 14:27
Joined
Jul 23, 2001
Messages
279
Ok...

I am getting this error message:

The expression On Click you entered as the event property setting produced the following error: Member already exists in an object module from which this object module derives.

* The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
* There may have been an error evaluating the function, event, or macro.

Here is what I am doing.

I am in a Form.
frm_SponsorData

I am clicking on a label.
btn_Close

The code behind the label is:
Private Sub btn_Close_Click()
cde_CloseForm
End Sub

The Function it is calling is in another module and is used by MANY forms. The Function is this:
Public Function cde_CloseForm()
On Error GoTo Err_cde_CloseForm

DoCmd.Close

Exit_cde_CloseForm:
Exit Function

Err_cde_CloseForm:
MsgBox Err.Description
Resume Exit_cde_CloseForm

End Function

Why is this not working?

I use this same Function from another form and it works just fine.
 

DBL

Registered User.
Local time
Today, 20:27
Joined
Feb 20, 2002
Messages
659
Make sure that in the module you don't have another OnClose event for that button that might be conflicting. Remove the surplace one and it should compile okay.
 

Randomblink

The Irreverent Reverend
Local time
Today, 14:27
Joined
Jul 23, 2001
Messages
279
Duplicates

Hey!

Excellent...
I think you are on to something...

Here is the situation...
I have multiple forms...
They ALL have the following:

Buttons:
btn_Close
btn_Delete
btn_InitiateDelete
btn_Delete
btn_CancelDelete
btn_Search

Listbox:
lst_SearchWindow

So FORM #1 has a btn_Close AND so does Form #2-5

You know how when you create a button using the Wizard to close the form, it will generate all the code for you? Well, I took that code, manipulated it, and created a Function in a completely different module.

Here is what my btn_Close looks like and operates like.

btn_Close

Private Sub btn_Close_Click()
cde_CloseForm
End Sub

in the seperate module I created, here is the function it is calling:

Public Function cde_CloseForm()
On Error GoTo Err_cde_CloseForm

DoCmd.Close

Exit_cde_CloseForm:
Exit Function

Err_cde_CloseForm:
MsgBox Err.Description
Resume Exit_cde_CloseForm

End Function

This way, I can create a button, name it btn_Close, and on the OnClick event for it, I just drop in the code cde_CloseForm and voila...I am finished.

What can I do now? How can I make this work?
 

DBL

Registered User.
Local time
Today, 20:27
Joined
Feb 20, 2002
Messages
659
The duplicate would only cause a problem if it's in the same module so if you have to OnClose events for BtnClose for Form 1 you'll get this error. It won't conflict between different forms. Look through your code for this form and see if you can spot two OnClose events for this button.

Just read the last bit again. If you have a public function to work on all btnClose and an OnClick event for btnClose on the form as well, that would give you the error I would imagine, take out the OnClick event.
 

Randomblink

The Irreverent Reverend
Local time
Today, 14:27
Joined
Jul 23, 2001
Messages
279
Works for You

Try this...

Create ANOTHER form...
create ANOTHER button...
Name it the same...
Now have it run the same code...
 

Jack Cowley

Registered User.
Local time
Today, 20:27
Joined
Aug 7, 2000
Messages
2,639
I have two forms with the same code and the command buttons are named the same. It works for either form. If both forms are open it closes the Active form...
 

Randomblink

The Irreverent Reverend
Local time
Today, 14:27
Joined
Jul 23, 2001
Messages
279
Never Mind

I don't have a clue what to do now...

Because I created a quickie database...
Created two forms...
Gave them BOTH the same exact naming on everything...
Click the button on both...no problem...

Let me go back and re-read everything...

Thanks for the help guys...
 

Fornatian

Dim Person
Local time
Today, 20:27
Joined
Sep 1, 2000
Messages
1,396
This is not an answer but you can save writing an event procedure, by typing:

=FunctionName()

in the Event Procedure line in the properties box.

If you have no other code in the form this would allow you to call the function and if possible remove the associated form module to make the form 'light'.
 

Randomblink

The Irreverent Reverend
Local time
Today, 14:27
Joined
Jul 23, 2001
Messages
279
Fornation vs. The World

Dude!

I had no clue that that would work!
Does that truly make your form light?

I can turn ALMOST everything on my forms into Functions that I can call just like that...

Does that reduce the size seriously? Or are you just guessing?
If that reduces the size I have to go back and fix the other forms AGAIN! Argh!

But, anything for the code...

That would be wicked bad, I would love that quite very much...

As for the PROBLEM I was having yesterday...

See, I created FORM #1 and got the code working on it...
Then I copied and pasted it with a new name...
I reassigned the Recordsource of all the fields, renamed them, and voila...

Well, I deleted that form now, and started over...

Suddenly I do not get the damn Member Already Exists bullcrap!
That was driving me outta my mind!


For those following my other post, I figured out the passing variables thing...

I pass them from my main form to a function, from there to the next function, and so on and so on...

Anyway...Let me know about the size thing...thanks!
 

Fornatian

Dim Person
Local time
Today, 20:27
Joined
Sep 1, 2000
Messages
1,396
Depending on how much module code you have wil depend on the efficiency saving - look at the form properties, you will see a property HasModule, it is usually set at yes but if you set it to no it will give a warning - then delete the associated module.

Think about a form of two halves - the form(itself, and controls placed upon it) and the associated form module). Stands to reason doesn't it that the fewer modules you have the smaller your db is - I am sure I am right but I can't prove it.
 

Randomblink

The Irreverent Reverend
Local time
Today, 14:27
Joined
Jul 23, 2001
Messages
279
Danka Shane Fornation

Thanks Fornation...

I agree with you on that one.

I am going to forgo using that for now...

But, my goal is to work towards that with my next version.

Thanks everyone, I am off to work...

All my quirks have been fixed!
Thanks to you all!
 

Fornatian

Dim Person
Local time
Today, 20:27
Joined
Sep 1, 2000
Messages
1,396
Supporting Evidence

Read the HasModule help - it supports my previous comments - glad to see I'm right sometimes(but not always) ;)
 

Users who are viewing this thread

Top Bottom