Using Checkboxes to choose data from a table.

Maherem

New member
Local time
Today, 03:15
Joined
Oct 13, 2012
Messages
5
[FONT=&quot]Where am i going wrong. I have a table tblMessages, with a yes/no column called Available I have a form with three checkboxes chk1, chk2, and chk3 the when i click chk1 the other two check should be checked which this code seems to do but what it is not doing is going to the table and selecting the data where the ID is 2. what am i missing here? it seems to go and check the first field on the table instead
thank you

Private Sub chk1_Click()
Dim strSQL As String 'Holds the SQL statement for this command only.
If chk1 = True Then
chk2 = True
chk3 = True
strSQL = "UPDATE'[Available]' FROM 'tblMessages' WHERE '[ID]'= 2"
Else
chk2 = False
chk3 = False
strSQL = "UPDATE '[Available]' FROM 'tblMessages' WHERE '[ID]'=2"
End If
Me.Requery
End Sub
[/FONT]
 
Last edited:
I just realized that the form did not have a DAO.Recordset hooked up and that was the problem. :D
 
Are you sure that this works.

Suggest that you test again with all possible options.
 
Are you sure that this works.

Suggest that you test again with all possible options.
That code did not work and I had to abandon it as soon I posted it :o. The problem was I didn’t use DAO.Recordset on the form load after that I just used
If chk1 =true then
CurrentDb.Execute(“UPDATE querTbl SET Available=True WHERE [Field Name2] = ‘field content’”)
Else
CurrentDb.Execute(“UPDATE querTbl SET Available=False WHERE [Field Name2] = ‘field content’”)
End if
Me.Requery
Took time putting all of it in every single checkbox but for now it works I will clean up the code at a when I clean up at the end.
If there is a better way of doing this I am open to suggestions.
Thanks:)
 
Suggest you fix it NOW.

Don't wait for a possible problem along the way.
 

Users who are viewing this thread

Back
Top Bottom