Re: DAO peculiarity in A97?



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
.



Relevant Pages

  • Re: ADO Query w/ Form Parameter Error
    ... After you open the recordset, BOF is true if no records were retrieved (that ... rst.movenext on an empty recordset, ... I have previously designated that strSession = Me.SessionID. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Replacement for Recordset Bookmark?
    ... Most of my declarations are at the head of the Sub - I didn't ... My code is less than optimal but the reason for the GoTo was that I have all ... > Are you using a recordset in VB.net or something else, ... > declaring the value types and using goto ExitMailSub in stead of Exit Sub. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SQL not working
    ... The SQL you're using to return the recordset only returns those rows that ... Function MergeStatusUpdates(E_Reference As String, E_RestructedFlag As ... rst.FindFirst strReference ... If rst.NoMatch Then GoTo Loop_Exit ...
    (microsoft.public.access.modulesdaovba)
  • Re: Empty "If Me.Recordset Is Nothing Then" clause causes runtime error 3021 (Access 2003)
    ... "If you delete the last remaining record in the Recordset ... I have some unresolved issues with requery/BOF/EOF, ... >> BOF and EOF are set by a MOVE command. ...
    (microsoft.public.access.formscoding)
  • Re: Empty "If Me.Recordset Is Nothing Then" clause causes runtime error 3021 (Access 2003)
    ... "If you delete the last remaining record in the Recordset ... I have some unresolved issues with requery/BOF/EOF, ... >> BOF and EOF are set by a MOVE command. ...
    (microsoft.public.access.forms)