Application-defined or object-defined error - Cant figure it out! Help

moto485

Registered User.
Local time
Yesterday, 23:06
Joined
Oct 18, 2011
Messages
50
Hi I have a problem and I just can't figure it out.

I have a pop up form that has a query in it that is filtered by what ever you enter in the txt box. The user then clicks on a record which first sends the data to a txt box (this part works) then I run Forms![Price List Matts Admin].btn_searchOrderCode_Click to click a button on the main form that has other code behind it that does its stuff, the subform then closes.

The problem is that running Forms![Price List Matts Admin].btn_searchOrderCode_Click keeps getting me this error:
Run-time error '2465':
Application-defined or object-defined error

I can't figure it out because I have the same code doing the same thing on another form working fine. This is an old system that I occasionally do work on.

Here is all the code that runs when you click on a record selector:
Private Sub Form_Click()
'This moves a order code to a txt box then clicks the button btn_searchOrderCode using vba.
'The button has code behind it that then runs.
'the sub form is then closed
Forms![Price List Matts Admin]!txt_search = Me.txt_OrderCode
Forms![Price List Matts Admin].btn_searchOrderCode_Click

DoCmd.Close acForm, "search_matts"
End Sub

If anyone has any ideas I would love to hear them.

Thanks.
 
Hi
You refer to 'pop-up form' and 'Subform' in your opening paragraph - I assume these are referring to the same thing?
I'm wondering whether your pop-up is calling its caller and thus causing a 'deadly embrace' (the caller can't proceed until the pop-up closes). I don't know whether or not this would produce the error you have.
Is the other instance you mention (which works) doing exactly the same thing? I'd suggest there is some subtle difference which allows one to work, but not the other.
Personally, I would not call a button click subroutine from other code. Perhaps you could put the button code into a separate subroutine, then call that from the button and form independently. If this can go in a shared module, it might help (but it might not, either:rolleyes:).
Have you checked the spelling of the entities involved (including the proper spacing in the form name)?
 
Yes sorry the 'pop-up form' and 'Subform' are the same thing.

I have checked the spelling many times and everything is okay and sending the data to the txt controls on the main form works.

I think it has something to do with button _click just not working on this form.
I added another button on the main form and ran the same thing and got the same error calling the _Click routine. I also created a new form with two buttons and ran the same thing but got the same error.

Is there something on the form that might be hindering the _Click ?
 
Replace Private with Public in the declaration of the handler
 
Well glad it's working now, I tried Public before but I failed to realise that the code behind the button on the main form was private! I was going nuts I think it was just to late in the night yesterday.

Thanks for you help!

Again answer for anyone else, check that all Subs are Public :)
 

Users who are viewing this thread

Back
Top Bottom