Results 1 to 4 of 4
  1. #1
    gazzieh is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    26

    Recordset Error

    If I run the following code:

    Set rst = db.OpenRecordset("tblBooking")

    Then it returns 7; the correct value

    If I alter this slightly:

    Set rst = db.OpenRecordset("SELECT * FROM tblBooking")

    Then it returns 1; obviously the wrong value.



    The reason why I wish to do this is because I actually wish to run the following:

    Set rst = db.OpenRecordset("SELECT * FROM tblBooking WHERE dteDate=#" & txtDate.value & "#")

    But this returns 1 (clearly since the first section returns an error.

    Why?

    Oh, BTW, I have set the following:

    Dim db As Database
    Dim rst As DAO.Recordset
    Set db = CurrentDb()

    The returning code is:

    lblNo.Caption = "There are currently " & rst.RecordCount & " bookings for that date."

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    That's not an error, it's a feature.

    http://www.baldyweb.com/RecordCounts.htm

    If that's all you want from the recordset, this would be more efficient:

    Set rst = db.OpenRecordset("SELECT Count(*) As HowMany FROM tblBooking WHERE dteDate=#" & txtDate.value & "#")

    lblNo.Caption = "There are currently " & rst!HowMany & " bookings for that date."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    gazzieh is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    26

    Smile

    Thanks for the response and the solution; both are perfect.

    Curiously, I have never come across this before and so never required this knowledge. Then again, I think I have only ever needed to know the recordset equalled at least 1 record.

    Anyhow, thanks very much.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Recordset
    By Rick West in forum Programming
    Replies: 7
    Last Post: 11-14-2011, 02:40 PM
  2. Recordset not updatable...WHY?
    By jgelpi16 in forum Queries
    Replies: 3
    Last Post: 11-30-2010, 08:40 AM
  3. Syntax Error Help with Recordset
    By ajetrumpet in forum Programming
    Replies: 11
    Last Post: 09-08-2010, 02:39 PM
  4. Replies: 0
    Last Post: 03-27-2010, 01:25 PM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums