Go Back   Access World Forums > Microsoft Access Discussion > General

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-02-2003, 09:16 AM   #1
Kevin_S
Registered User
 
Join Date: Apr 2002
Location: Lansing, MI
Posts: 635
Thanks: 0
Thanked 2 Times in 1 Post
Kevin_S is on a distinguished road
Error 2424 Object not found...

Hi Everyone,

I have to post this because it is: (1) Driving me INSANE 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

__________________
MCAD .NET
MCP VB.NET
MCP C#.NET
Kevin_S is offline   Reply With Quote
Old 06-02-2003, 09:20 AM   #2
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 26,462
Thanks: 12
Thanked 1,226 Times in 1,168 Posts
Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light
Make sure that you are referencing the name of the control rather than the name of the bound field.
Pat Hartman is offline   Reply With Quote
Old 06-02-2003, 09:26 AM   #3
Kevin_S
Registered User
 
Join Date: Apr 2002
Location: Lansing, MI
Posts: 635
Thanks: 0
Thanked 2 Times in 1 Post
Kevin_S is on a distinguished road
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

__________________
MCAD .NET
MCP VB.NET
MCP C#.NET
Kevin_S is offline   Reply With Quote
Old 06-02-2003, 09:49 AM   #4
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 26,462
Thanks: 12
Thanked 1,226 Times in 1,168 Posts
Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light
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?
Pat Hartman is offline   Reply With Quote
Old 06-02-2003, 10:08 AM   #5
Kevin_S
Registered User
 
Join Date: Apr 2002
Location: Lansing, MI
Posts: 635
Thanks: 0
Thanked 2 Times in 1 Post
Kevin_S is on a distinguished road
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
__________________
MCAD .NET
MCP VB.NET
MCP C#.NET
Kevin_S is offline   Reply With Quote
Old 06-02-2003, 10:16 AM   #6
Rich
Guest
 
Posts: n/a
Use the timer event
  Reply With Quote
Old 06-02-2003, 10:24 AM   #7
Kevin_S
Registered User
 
Join Date: Apr 2002
Location: Lansing, MI
Posts: 635
Thanks: 0
Thanked 2 Times in 1 Post
Kevin_S is on a distinguished road
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

__________________
MCAD .NET
MCP VB.NET
MCP C#.NET
Kevin_S is offline   Reply With Quote
Old 06-02-2003, 10:50 AM   #8
Rich
Guest
 
Posts: n/a
I wouldn't advise running the code alongside your clock, clutching at straws, have you tried DoEvents?
  Reply With Quote
Old 06-02-2003, 11:09 AM   #9
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 26,462
Thanks: 12
Thanked 1,226 Times in 1,168 Posts
Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light
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.
Pat Hartman is offline   Reply With Quote
Old 06-02-2003, 11:32 AM   #10
Kevin_S
Registered User
 
Join Date: Apr 2002
Location: Lansing, MI
Posts: 635
Thanks: 0
Thanked 2 Times in 1 Post
Kevin_S is on a distinguished road
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
__________________
MCAD .NET
MCP VB.NET
MCP C#.NET
Kevin_S is offline   Reply With Quote
Old 06-02-2003, 12:57 PM   #11
Rich
Guest
 
Posts: n/a
Try re-naming pickFill to txtPickFill on the property sheet, If Me.txtPickField etc
  Reply With Quote
Old 06-03-2003, 04:48 AM   #12
Kevin_S
Registered User
 
Join Date: Apr 2002
Location: Lansing, MI
Posts: 635
Thanks: 0
Thanked 2 Times in 1 Post
Kevin_S is on a distinguished road
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

__________________
MCAD .NET
MCP VB.NET
MCP C#.NET
Kevin_S is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 12:59 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World