Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

section of code generates an error, HELP

Status
Not open for further replies.

GabberGod

IS-IT--Management
Nov 16, 2003
73
0
0
AU
Private Sub Allocated_AfterUpdate()
Dim frm As Form

Set frm = [Forms]![Jobs Entry]

If [Allocated] = True Then Me!Job = frm![Job]

Set frm = Nothing
End Sub

this piece of code works fine, but generates the following error.

"An error occured, while referencing the object. You tried to run a vis basic procedure that improperly references a property or method of an object"

HELP PLEASE, i need this code to be invisible
 
Is by chance [Jobs Entry] a subform ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
no Jobs Entry is the main form, the code is actually on a subform itself, it references the main form to find the job code that has been entered. then if the allocated box is ticked, the job code is placed in that items job field.

basicly attaching items to a job.
 
So the main form and the subform have both a control named Job ?
If yes, you may try this:
Private Sub Allocated_AfterUpdate()
If Me!Allocated Then Me!Job = Forms![Jobs Entry]!Job
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
nope that did not work

any other suggestions?
 
nope that did not work
Any error message ? Any code highlighted when in debug mode ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
So, how are you sure that this is this piece of code that raise the error ?
Have you tried to set a breakpoint and then step the code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
when i preform the function that runs the code i get an error, seems to me it must be that piece of code no?

i.e the code is an after update event, when i update the allocated field by ticking a box, it places value in the job field of the subform and displays the above error.

no i havent set a breakpoint and stepped throught the code. I didnt think it was complex enough to need it.

explain please
 
I suggested to debug the (one line) code as I guess the error is raised elsewhere ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
i dont understand, what are you telling me to do???

sorry i can only write the code, i havent got alot of understand how it all works, i dont use access or visual basic often, i just learned the syntax.
 
...not complex enough to need it." - But really, how much effort does it take to step through a few lines of code???

When you have experience and skill with some form of programming, and you hit a conflict between code which seems like it couldn't possibly be wrong and an error which is nevertheless occurring, it's almost always going to be the case that something's wrong with your assumptions. The best approach is to abandon all assumptions and act like you don't understand the code. PHV is right, you need to step through this.

One possibility is that it isn't this code that's failing at all. In fact, the Job field is being filled in on the subform, so it would seem that the only statement that could be failing is the "Set frm = Nothing" - and anyone with a little experience would agree that that statement can't fail (given that "frm" is an object variable).

My hunch is that this procedure is working fine, but some later event is throwing the error. Perhaps you have an accidental entry in another event property, or perhaps instead of cutting and pasting the procedure you typed it in, inadvertently omitting erroneous code or correcting a typo. In either case, stepping through the code will probably isolate the error to a particular line, which will better focus your diagnostic thoughts.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
well thanks and all for the explaintion of what steping through code is, again i should be more specific

HOW DO I DO THAT???
 
So, your event procedure should be now like this:
Private Sub Allocated_AfterUpdate()
If Me!Allocated Then Me!Job = Forms![Jobs Entry]!Job
End Sub
Just press F9 when the cursor is on the code
Then play with your form, changing the Allocated checkbox will put you in debug mode.
The step by step is done by pressing the F8 key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
GabberGod, I'm sorry, I was writing my post as you replied to PHV's, so I didn't have the information that you didn't know how to do it. You seemed to be familiar with writing code in your earlier posts.

I see PHV is actively tracking this, so I'll leave you in his or her capable hands.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thank ypou guys, ill give that a try asap, got a meeting now
 
OK well I removed the code from the field all together and when i click, i still get the error.

Basicly the subform is based on a query which pulls a select group of fields from a table, it the idea is that the fields are already populated with data, they just need to be allocated to a job, so buy ticking a box you allocate it to a job.

Any ideas why a boolean field would cause such a problem???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top