Re: DAO peculiarity in A97?
- From: Tim Marshall <TIMMY!@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 31 Dec 2005 16:31:01 -0330
MLH wrote:
is the case. I'm wondering if my code in line 231 might be flawed in light of the fact that qdfType17CorrespRecs returns no records?
M, I note that you have line 231 commented out. The commenting out would prevent the action in lieu of an empty recordset (in this case, goto rec - see comments on this construct, later) from ocurring.
However, assuming you get this error with the comment removed...
Personally, whenever I open a recordset, I always check for .eof immediately afterward and if true, close the recordset and go on. My experience has been that I only ever bother with .bof when I'm working backwards in a recordset.
However, from discussion I've seen on cdma a couple of times, I seem to recall that some folks who know what they are talking about say they always check for an empty recordset by checking .bof and .eof, but my above convention has never failed me _for the stuff *I* do_.
But as I said, I think your code would work with the .BOF if it wasn't commented out.
Two things.
First, If 231 is not commented out, I wonder if your later code does something with the recordset anyway even if .bof is true where you test that? It would be well worth your time to add a breakpoint just before your line 91 and then step through your code that way to make sure.
Second, you're using goto. Long before I got into VBA (and, in fact, before VBA ever was, or at least before VBA was commercially available) it's always been a basic tennant of programming that using goto is bad practice. I agree with this, though I use it in one exception, and that's goto Exit_Proc, ie, instead of just putting in a exit sub/function, I endeavour to have one and only one exit point from my procedures. Though ideally, a well designed series of if/endifs and loops is better. It also makes it easier to avoid the sort of problem you've described if there is a definite progressive structure to your logic rather than the sort of jumping out of things that use of GoTo encourages.
Another thing you've done is having a line of code:
Do Until rstType17CorrespRecs.EOF
But you have that within a With rstType17CorrespRecs loop.
Here's what I would do with the code you've presented, removing the comments, instead of the goto NoRecs label.
What you've done, nesting with/end with, is legal, but I prefer not to do it myself as I find it can get confusing, but that's just my personal preference - unlike my adage on avoidance of use of GoTo which is universal good practice.
With MyDB
Set qdfType17CorrespRecs = .CreateQueryDef("", "Select * " & _
"FROM tblCorrespondence")'TIM COMMENT - you don't need the semi-colon
With qdfType17CorrespRecs
' Open Recordset from QueryDef.
Set rstType17CorrespRecs = .OpenRecordset(dbOpenSnapshot)
With rstType17CorrespRecs
If .EOF = False Then
.MoveFirst
Do Until .EOF 'See my comment immediately preceeding!
<do stuff>
Loop
Else
'This is where you'd do the stuff with your NoRec Label
End if
End With ' for rstType17CorrespRecs
End With 'for qdfType17CorrespRecs
End With 'for MyDB
There'a another way I do things, especially if I have a lot of Do/Loops, For/Eaches, If/EndIfs which involves declaring a boolean, booProceed and things like .EOF or other show stoppers set booProceed to false.
-- Tim http://www.ucs.mun.ca/~tmarshal/ ^o< /#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake /^^ "What's UP, Dittoooooo?" - Ditto .
- References:
- DAO peculiarity in A97?
- From: MLH
- DAO peculiarity in A97?
- Prev by Date: Re: DAO peculiarity in A97?
- Next by Date: Re: detail section in a report
- Previous by thread: Re: DAO peculiarity in A97?
- Next by thread: Re: DAO peculiarity in A97?
- Index(es):
Relevant Pages
|