Error 2424 Object not found... (1 Viewer)

Kevin_S

Registered User.
Local time
Yesterday, 23:08
Joined
Apr 3, 2002
Messages
635
Hi Everyone,

I have to post this because it is: (1) Driving me INSANE :eek: and (2) I can't for the life of me figure out what is going wrong so here goes....

I have an unbound form that, at runtime, is given a recordsource of 1 of 2 queries depending on the users selection on the previous form through the double-click event of a listbox with this snippet of code:

[Forms]![frmVac_Log].RecordSource = "qryVac_Log"

Simple enough and everything works great.

Now - what I want to do is hide or display a few controls on the form depending on a selection in the form with a simple If-Then-Else statement like this example:

If (This field) = 1 then
'Display this control
else
'Display that control
end if

Very, very simplified HOWEVER When I put this If-Then statement in ANY Event Procedure (On Open, Current, Activate, Load,etc...) It errors and gives this message:

Runtime Error '2424'
The expression you entered has a field, control, or property that Microsoft Access can't find

And it highlights the first line in the if-then code

Everything is spelled correctly and the references are set right - no spelling errors or nothing...

Anyone have any ideas why this is happening?

Thanks,
kev
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:08
Joined
Feb 19, 2002
Messages
43,233
Make sure that you are referencing the name of the control rather than the name of the bound field.
 

Kevin_S

Registered User.
Local time
Yesterday, 23:08
Joined
Apr 3, 2002
Messages
635
Hi Pat,

I just double checked it and the If-Then points to the correct name "pickFill" and not the bound field. The code errors, and then highlights this in the debug window:

If Forms!frmVac_Log!pickFill = 1 Then

I tried using me. as well to no avail.... I thought it might be triggering because the control in question is an option group so I tried to have the If-Then just look a the value of a text field and run but I got the same error - is this typical with unbound forms based on queries or am I getting an error for some other reason...?

Thanks for Your Help,
Kevin
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:08
Joined
Feb 19, 2002
Messages
43,233
If the value changes for every record, the correct event for the code is the Current event.

Use the Me.Yourname syntax. When you type Me. - you should then see an intellisense list of properties/method. The control name should be in that list. Is it?
 

Kevin_S

Registered User.
Local time
Yesterday, 23:08
Joined
Apr 3, 2002
Messages
635
Pat,

The control name is indeed in that list WHEN I have the form's recordsource set as the query. This is the way I built the form (with the recordsource being the query) But - for using the form in the application I remove the recordsource for the form in design view, as I am setting this property on the fly through the listbox selection on the previous form. Both possible recordsource selections in the listbox have this field as one of the controls in the queries.

THis is so weird..? I tried creating a new db and importing all objects (figuring I might have a corrupt db or something) but nothing helped....

Any other ideas?

Thanks Pat,
kev
 

Kevin_S

Registered User.
Local time
Yesterday, 23:08
Joined
Apr 3, 2002
Messages
635
Hi Rich/Pat,

Rich- I am already using the form timer event to display the current date/time in a digital clock fashion. Can I add additional code to the event and have this function still work correctly (I'm not real handy with the Timer event as I hardly ever use it except for digital time display purposes. If there is a solution in the use of this event that would be great - as long as it doesn't interfer with its current use (for some reason my users LOVE this display even though I tell them time and again all you have to do is mouseover the taskbar at the bottom of the screen to see the time...)

Additional Note:

This error has to have something to do with the code running BEFORE the form gets the recordsource because if I move the code to the Mousemove event in the detail section of the form everything works fine but - I feel like this is a cheap work-a-round and I think that this will waste resources having the code continuously firing on the movement of the mouse... thoughts on this or the timer event...?

Thanks,
Kev
 
R

Rich

Guest
I wouldn't advise running the code alongside your clock, clutching at straws, have you tried DoEvents?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:08
Joined
Feb 19, 2002
Messages
43,233
There is no need to remove the recordsource that you used to create the form. I always leave it otherwise, I run into trouble if I need to modify the form.

Control names will NOT disappear from the intellisense list when you remove/change the recordsource. Only bound field names would disappear. If the name you are using disappears, it is the name of the bound field, not the name of the control.

The control names should be different from the names of the fields they are bound to. This is good practice in any event. There are a number of occasions where confusion can occur regarding whether your code is attempting to reference the control and its properties or the bound field.

And I'll remind you one more time, the Current event is the event to use if you want the code to run whenever the current record pointer is moved to a different record.
 

Kevin_S

Registered User.
Local time
Yesterday, 23:08
Joined
Apr 3, 2002
Messages
635
Thanks Pat/Rich for the continued help...

Rich - I tried DoEvents and it still didn't solve the problem

Pat - The reason I have the form unbound is that, based on a selection in a listbox on a previous form, the form frmVac_Log can have 1 of 2 possible queries as the recordsource. If I hard code the recordsource to the form in design view then I have issues trying to set it on the fly. The name never disappears from the list - I misspoke and was looking at the bound field.

I still can't get this to work so if either of you have any other possible suggestions I'd love to hear them... if not I'll just go with the work-a-round.

Thanks Again,
Kevin
 
R

Rich

Guest
Try re-naming pickFill to txtPickFill on the property sheet, If Me.txtPickField etc
 

Kevin_S

Registered User.
Local time
Yesterday, 23:08
Joined
Apr 3, 2002
Messages
635
Hi Pat/Rich,

I just wanted to thank both of you for trying to help me get this resolved. I was never able to get the form to allow me to hide/unhide the boxes on the opening of the form in the On Current event - the cause of the problem was that in the code on the form that opens the form in question I open the form and then set the recordsource to the query that was selected in the listbox - I had to assign the recordsource after the form is opened because when I tried to assign the recordsource first the code errored as it couldn't find the object so... the on Current event fired before the form had a recordsource and, consequently, the db couldn't find the fields in question.

So - to fix this problem - I added the If/Then code to the code that opens the form on the Double-Click event of the listbox - this way the code opens the form THEN assigns the selected Query as the recordsource THEN test the value of the field and hide/unhides the fields depending on the value of the option group. THis method is not as efficient as the On Current event would be but it is definitly more efficient then the On Mousemove event.

Thanks for you help with this - it really helped me determine what the problem was and where it was occuring.

Kevin
 

Users who are viewing this thread

Top Bottom