Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add record to recordset via checkbox 1

Status
Not open for further replies.

BrockLanders

Programmer
Dec 12, 2002
89
US
Hi, I have a form in my Access 2000 db and I want to select any number of records, using a checkbox and then add those to a recordset. However, the checkbox is only on the form and is not located in a table.

Any ideas because I'm stumped.

Thanks much in advance
 
Well Brocklanders, If I understand correctly...

I would assume, each record has a unique ID. If so...

Create a SQL, appending a new criteria each time a checkbox is checked.

Dim strSQL as String

strSQL = "SELECT * FROM tblTable "

If chk1 Then strSQL = strSQL & "WHERE pkRecordID=" & Me.pkRecordID

If chk2 Then strSQL = strSQL & "OR pkRecordID=" & Me.pkRecordID

...actually, this may not be the setup you have.
Is it, one checkbox per record? If so..

Create a global variable
Const SQL = "SELECT * FROM tblTable "
Public strWhere As String

Then, on the click event of chkbox

If chkBox Then strWhere = strWhere & " pkRecordID=" & Me.pkRecordID & " OR "

Then, with a command button, onclick event.

see if strWhere is populated
If strWhere = "" Then
Recordset = SQL
Else
Recordset = SQL & "WHERE " & Left(strWhere,Len(strWhere) - 5)

Is this the idea?







 
My setup is like your 2nd scenario with 1 checkbox per record. I used your code and it worked perfectly.

Thanks much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top