IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Access: Runtime error 91.
I keep getting this one: "Run-time error 91: Object variable or With block variable not set".

I'm not sure why. It crops up when there is another error message (ANY error message). I'm using object variables to keep track of certain aspects of the current records, so I'm assuming that any error message sets all object variables to Empty? I am unsure as to how to trap these into not doing this.
New I think that one means...
..."Go and get a proper database!"

GD&R


Peter
[link|http://www.ubuntulinux.org|Ubuntu Linux]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Home]
Use P2P for legitimate purposes!
New Re: I think that one means...
The problem is, I have historically neglected to pay much attention to proper error handling.
New From the 10 Commandments of C Programming:
#6: If a function be advertised to return an error code in the event of difficulties, thou shalt check for that code, yea, even though the checks triple the size of thy code and produce aches in thy typing fingers, for if thou thinkest ``it cannot happen to me'', the gods shall surely punish thee for thy arrogance.


And yes, it applies to VB as well. :)
"Here at Ortillery Command we have at our disposal hundred megawatt laser beams, mach 20 titanium rods and guided thermonuclear bombs. Some people say we think that we're God. We're not God. We just borrowed his 'SMITE' button for our fire control system."
New So.
How does one go about making a global error handler?
New In VB?
On Error Resume Next was the most popular method I saw. I wouldn't recomend it myself.

Jay
New Re: In VB?
Yes.
New You can use On Error GoTo
Or at least you could way back in the day.

I don't know whether Microsoft has now added some form of exception handling to the language. If they did, then use that instead. (Unless it is really, really broken.)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New That's still the way
It's the way Microsoft still does it with the auto code in Office 2003

Private Sub Button_Click
On Error Goto err_Button_Click
   code
   ...
exit_Button_Click:
   Exit Sub
err_Button_Click:
   Msgbox Err.Description
   Resume exit_Button_Click
End Sub


after the err_whatever: tag, you can set up code to compare the Err.Code and handle whatever errors you expect.
~~~)-Steven----

"I want you to remember that no bastard ever won a war by dying for his country.
He won it by making the other poor dumb bastard die for his country..."

General George S. Patton
New That was a joke
That was a joke, not a programming idea. On Error Resume Next tells VB to simply continue with the next step when there is an error. This causes all sorts of havok when there is a real problem.

But if you want a really global error trap, then either put the entire program inside a try/catch block or a global On Error statement at the start.

There isn't much you can do in VB if you catch errors at that level though. All you can do is present some formatted error information and quit.

Jay
New For certain techniques, it works.
Specifically, the practice of manually checking ErrCode after steps that could catastrophically fail. It's a bit lazy, though for some types of code, the risk of an uncaught error is suitably low.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Opinions vary on "Global" error checking in VB.
But in general, it is thought to be a bad idea. I'm in that camp.

bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
New That's the technical term "set"
Most likely, you have a bare assignment like

Object = New Thing

...that should be using the Set command instead:

Set Object = New Thing
New Re: That's the technical term "set"
I am, in fact, using Set:

Set cls_BatchALSAdd = New clsBatch


I am believing more that I need to trap all my own errors to avoid having Access void the objects when it generates an error. I do not want to do this by putting an On Error Goto Errhandler in each and every procedure though. Can't figure out where to put it though. I can't put it outside of a procedure, but otherwise I (think I) have to put it in every procedure.
New Yes, unfortunately.
Which is why trapping sucks as a debug technique in VB/VBA. Liberal use of debugger breakpoints will point out the offending code quicker. Which still isn't fun. :(
New Putting it in every procedure is good practice for VB.
Even if it's just to write to an error log and continue. I've been coding VB for more years than I care to admit (Versions 3-6, am doing a lot less now), but I always made every "Sub" routine a Function that I could and returned a boolean. Each Sub and Function had its own error trap. Sucks, but there you are.
bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
New Dangitall.
Oh well, I guess I shall start putting them in. . . .*sigh*
New Update: (+edit)
I must amend my previous musings on what is happening. It appears as though a recordset reference is being lost somewhere when an error message is generated. I declare said recordset thusly outside of any procedures:

Dim rst As DAO.Recordset


In the Form_Load Sub I set it:

Set rst = CurrentDb.OpenRecordset("tblALS_Add", dbOpenDynaset)


This is referencing a different table from the one in current use by the form (I'm doing on-the-fly data entry verification). tblALS_Verify is the current table being used by the form, tblALS_Add is the outside one it is checking against).

After any old error message, this bit causes the problem:

rst.FindFirst strCriteria


It can't, apparently, find any reference to rst anymore. So I assume when a runtime error occurs, those references get dropped. Is there a different way of declaring these or Setting them so this won't occur?

[Edit] Yes, I know DAO is old. It's partially legacy code.
Expand Edited by acagle Dec. 29, 2004, 12:57:53 PM EST
New You're probably all over this, but...
have you verified that the reference is turned on for 'Microsoft DAO 3.6 Object Library' that it's higher priority than ActiveX Data Objects (I usually turn the latter off altogether)?

Personally, I define my recordset objects within my procedures, and if it's needed in another procedure I'll pass the reference in my parameters. Just remember to 'SET rst = Nothing' at the end of the defining procedure to clear the reference.

And yes I still use DAO regularly myself. I'm just more accustomed to it.
~~~)-Steven----

"I want you to remember that no bastard ever won a war by dying for his country.
He won it by making the other poor dumb bastard die for his country..."

General George S. Patton
New Re: You're probably all over this, but...
Yeah, I figured that 3.6 stuff out a while ago. I also discovered the original app I borrowed the code from almost does the same thing, but there are pseudo-error traps that keep it from erroring out. But the basic behavior is the same (it pops up the hard-coded error message a couple times before letting you kill it).

So anyway. . . . .the options aren't looking too good unless there's some way to get Access to stop dropping the reference on an error message.
New Where is the declaration exactly? And a few more q's.
1) I assume the declaration is in a bas module (not Form module), yes?

2) Is the same rst object used to hold different recordsets across multiple forms?

3) Could you post the Form_Load and Form_Activate code?

4) If you write an error handler in the form_load that looks something like this, what is written to your c:\\myerrors.log file?

Form_Load()

On error goto Load_Err

...

Load_Exit:
Exit Sub

Load_Err:
' I don't remember if DAO has an errors collection or not, but I think it does.
' If it doesn't, strike out the errX stuff below
Dim hFile as long
Dim errX as Error

hFile = Freefile()
Open "C:\\MyErrors.log" for Append as #hFile
Print #hFile, Err.Description
For Each errX in DAO.Errors
Print #hFile, errX.Description
Next errX
close #hFile
Resume Load_Exit
bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
Expand Edited by mmoffitt Dec. 30, 2004, 12:40:15 PM EST
New Did you get this fixed?
bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
New Re: Did you get this fixed?
Oops, forgot to get back. (I've been having employment issues)

I mostly solved it, but by punting. I've just gone after each individual instance that's causing an error message and dealing with it that way. So instead of going through and putting an error handler in every.single.Sub. I am just dealing with individual errors when they come up and making sure it doesn't error out to a run-time error message.

I need to fix this in future projects though. . . . .
     Access: Runtime error 91. - (acagle) - (22)
         I think that one means... - (pwhysall) - (10)
             Re: I think that one means... - (acagle) - (9)
                 From the 10 Commandments of C Programming: - (inthane-chan) - (8)
                     So. - (acagle) - (7)
                         In VB? - (JayMehaffey) - (5)
                             Re: In VB? - (acagle) - (4)
                                 You can use On Error GoTo - (ben_tilly) - (1)
                                     That's still the way - (Steven A S)
                                 That was a joke - (JayMehaffey) - (1)
                                     For certain techniques, it works. - (static)
                         Opinions vary on "Global" error checking in VB. - (mmoffitt)
         That's the technical term "set" - (FuManChu) - (4)
             Re: That's the technical term "set" - (acagle) - (3)
                 Yes, unfortunately. - (FuManChu)
                 Putting it in every procedure is good practice for VB. - (mmoffitt) - (1)
                     Dangitall. - (acagle)
         Update: (+edit) - (acagle) - (5)
             You're probably all over this, but... - (Steven A S) - (1)
                 Re: You're probably all over this, but... - (acagle)
             Where is the declaration exactly? And a few more q's. - (mmoffitt)
             Did you get this fixed? -NT - (mmoffitt) - (1)
                 Re: Did you get this fixed? - (acagle)

There should be an opportunity for somebody here.
310 ms