Checking/Unchecking All Records

Shop Girl

Registered User.
Local time
Today, 15:40
Joined
Sep 2, 2002
Messages
18
Can someone help me on this one - I have a database that was set up using the contacts database wizard - One useful feature I'd like to keep is just not working - it did in the begininng - but since adding my own stuff to it its not working anymore! This piece of code falls over at rs.edit - compile error: Method or data member not found. But I did not write this code - it was already there...

Private Sub ckPrintFlag_AfterUpdate()
On Error Resume Next
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
End Sub

Private Sub ckSelect_AfterUpdate()
' If clicked, then select all records
' and change label caption. If false,
' then de-select all records and change
' label caption.

On Error GoTo HandleErr

Dim rs As Recordset

Me.Refresh
Set rs = Me.RecordsetClone
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
rs.Edit
rs!PrintFlag = (Me!ckSelect = True)
rs.Update
rs.MoveNext
Loop
End If
Me.Refresh

If Me!ckSelect = True Then
Me!lblSelect.Caption = "Clear all contacts"
Else
Me!lblSelect.Caption = "Select all contacts"
End If

ExitHere:
On Error Resume Next
rs.Close
Exit Sub

HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, , _
"Form_PrintLabelsSub.ckSelect_AfterUpdate"
End Select
Resume ExitHere
End Sub

Any ideas please?
 
Have you edited any of the field names in the table that feeds that form. Does the "PrintFlag" field still exist. Because your recordsetclone is looping through to change all of the "PrintFlag" fields in the recordset to True. Although I have to admit that it seems strange to see rs!PrintFlag = (Me!ckSelect = True)....hmmmm
 
No I haven't changed any of the field names and yes printflag still exists (its a check box)
 
Are you using Dao ? or Ado.... In Ado you don't have a .edit method :)

The code you wrote looks like Dao.. :/


Vince
 
I didn't write the code - It just lives in the Contacts Database example that comes with Access - It must be ADO where rs.edit doesn't exist because if you try to retype this it only comes up with rs.editmode - but none of us here know what we can replace this with to get it to run or even if its possible :o .

I have added to the forms and tables - but I haven't touched the coding of this db at all.
 
You are probably using ADODB as your default data access method (this is true for A2000 and A2002).

The Me.Recordsetclone method, however, is DAO. You should change your code to DAO. This is quite simple and will only involve the setting of a reference.

My FAQ here will help you to do this.
 
Also, ensure your code is consistent and efficient:

Change:

rs!PrintFlag = (Me!ckSelect = True)

to

rs.Fields("PrintFlag") = (Me.ckSelect = True)


Anyway, if it's a case of just unchecking or checking all records then you can just use an UPDATE Query and not bother with all this more complicated stuff.
 
Remark the line out with a single quote... It'll remove it from processing but leave it in the code incase you need it.

[vbcode]
' rs.edit
[/vbcode]


Vince
 
Thanks for all your help on this one :)

I'm now a happy bunny - changing the references via the module's tool menu worked a treat.

And of course I could of used an update query - I've done that before - doh!

Thanks once again
 

Users who are viewing this thread

Back
Top Bottom