n00b question

border20

Registered User.
Local time
Today, 12:39
Joined
Jan 8, 2003
Messages
92
I have a table with a field that is only a check box that can either have the value true or false... what would ba the VB code, or what fonction should i use if I want to check all the unchecked boxex in that field

thx Frank
 
.

thx but I knew that... I was wondering how exactly to midify the fields from scratch... like

Command11_Click()

-=CODE=-

What finction is used to modify the values in tables ?
 
On a form you would do it like this:
Code:
Private Sub cmdToggleCheck_Click()

If Me.chkSample = True Then
    Me.chkSample = False
ElseIf Me.chkSample = False Then
    Me.chkSample = True
End If

End Sub

To loop though an entire table you would use something like this:
Code:
Dim rsFieldCK As DAO.Recordset
Dim strCheck As String
Set rsFieldCK = CurrentDb.OpenRecordset("TableName")
    
Do While Not rsFieldCK.EOF
    rsFieldCK.Edit
    rsFieldCK.Fields("FieldName").Value = True
    rsFieldCK.Update
    rsFieldCK.MoveNext
Loop
Set rsFieldCK = Nothing
Again you could use an If Then to toggle the check boxes similar to the If Then on the form example.
 
So if you want to toggle the values in the table with code here is the Sub:
Code:
Private Sub cmdToggleCheck_Click()

Dim rsFieldCK As DAO.Recordset
Dim strCheck As String
Set rsFieldCK = CurrentDb.OpenRecordset("TableName")
    
Do While Not rsFieldCK.EOF
    If rsFieldCK.Fields("FieldName").Value = True Then
        rsFieldCK.Edit
        rsFieldCK.Fields("FieldName").Value = False
        rsFieldCK.Update
        rsFieldCK.MoveNext
    ElseIf rsFieldCK.Fields("FieldName").Value = False Then
        rsFieldCK.Edit
        rsFieldCK.Fields("FieldName").Value = True
        rsFieldCK.Update
        rsFieldCK.MoveNext
    End If
Loop

Set rsFieldCK = Nothing

End Sub
 
eish

Thx alot for your help but... I used the folowing code (because i only want to change unchecked to checked)


Dim rsFieldCK As DAO.Recordset
Dim strCheck As String
Set rsFieldCK = CurrentDb.OpenRecordset("Alarme")

Do While Not rsFieldCK.EOF
If rsFieldCK.Fields("Message envoyé").Value = False Then
rsFieldCK.Edit
rsFieldCK.Fields("Message envoyé").Value = True
rsFieldCK.Update
rsFieldCK.MoveNext
End If
Loop

Set rsFieldCK = Nothing

But it made My access crash .... dont know why ... (Access 200)
anyone know why ?
 
You didn't mention the error but since you are on Access 2000 and I did mine in Access 97 I bet you do not have the reference to ADO checked. Start a new module and then go to Tools > References and make sure Microsoft DAO 3.6 Object Library is turned on.

I just tried the code on a Access 2000 DB with that reference off and I errored. After I checked it the code worked fine. It should for you also.
 
not it

Actualy there is already a reference to DAO 3.6
 
What is happening when the code is run? Is there any error number being shown?
 
border20,

Where does it die?

Set a breakpoint on your first executable line.
When in debug mode single-step thru with F8 and note
when it dies.

Wayne
 
darn...

I tried what the thread said... and same result...

BukHix- The program just crashes... program not responding and i have to use the good old ctrl+alt+del

:(
 
Hi border20,

You're in an infinite loop. If the value is false, you never to
to the next record.

Wayne
 
I'm curious, what advantage is there in looping through a table in code when an Update Query will perform 500-1000 times faster?
 
You use the update query to update fields in a table. Rich is right it would be easier to do it that way.

Rich I prefer doing things in code because of the work I do with ASP. And I try not to rely on MS Wizards at all even when I probably should.
 
hmm

How is update query used ? cant seem to find it in the help files...
 

Users who are viewing this thread

Back
Top Bottom