Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help with VB Code (MS Access 2000)

    Hi...I'm a novice and need any help possible.

    I'm using Access 2000, referencing DAO.

    I have a query called "qryCheckOff"

    In my form I show continuous records from this query. I would like a button with an "OnClick" event that will set the value of my "CheckOff" field to True for all my records. But I have no idea really how to do this. What I've got so far is:

    Private Sub cmdCheckBox_Click()

    Dim db As Database
    Dim rec As Recordset

    Set db = CurrentDb()
    Set rec = db.OpenRecordset("qryCheckOff", dbOpenDynaset)

    Do
    rec!CheckOff.Value = True
    rec.MoveNext
    Loop Until rec.EOF
    rec.Update
    rec.Close

    End Sub

    --This gives me an error on the "rec!CheckOff.Value = True"

    Can anyone put me on the right track? Thanks in advance.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Need Help with VB Code (MS Access 2000)

    When updating information in a recordset, you need to use the .Edit and .Update methods. Your code should look like this:

    Do
    rec.Edit
    rec!CheckOff.Value = True
    red!Update
    rec.MoveNext
    Loop Until rec.EOF


    A better and faster way, however, is to use an update query (see Access Help).
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    New Lounger
    Join Date
    Aug 2002
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need Help with VB Code (MS Access 2000)

    Thank you Mark. You solved my problem quickly. I appreciate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •