access vba - How can one find and delete a record in a DAO Recordset where two record values are equal to two separate combo boxes on a form -
i have access 2010 form:
the activity roster table looks this:
i remove member given activity , have developed code think close, cannot resolve critical issue. have find row in activity roster table has record activityid , memberid values correspond “activity name” combo box , “remove member” combo box. here code:
private sub cmdremovemember_click() dim membeid long, cutmemid long, actid long dim db dao.database, rsin dao.recordset, rsout dao.recordset set db = currentdb dim strqname string cutmemid = me!cbocutmember.column(0) 'set value of cutmemid memberid remove member combo box actid = me.cboactivityname.column(0) 'store actid activity name combo box 'query tblactivityroster records specified activity id (name)- generates qactivitymembership query strqname = "select * [tblactivityroster] [activityid] = " & actid set rsin = db.openrecordset(strqname, dbopendynaset, dbreadonly) rsin.movelast 'this "populate recordset" 'prepare remove member tblactivityroster set rsout = db.openrecordset("tblactivityroster", dbopendynaset, dbeditadd) rsout.movelast 'this "populate recordset" rsout 'from tblactivityroster, find record activity id = actid , memberid = cutmemid until rsout.eof if rsout![activityid] = actid , rsout![memberid] = cutmemid 'this if fails!! rsout.delete end if rsout.movenext loop end me.qactivitymembership_subform.form.requery 'now close query docmd.close acquery, strqname 'now clear rsin.close rsout.close set rsin = nothing set rsout = nothing set db = nothing end sub
would appreciate help…thank you!
micheal,
your code looks taking long way around. why not use delete query? sample:
private sub cmdremovemember_click() dim cutmemid long, actid long, strqname string dim db dao.database set db = currentdb cutmemid = me!cbocutmember.column(0) 'set value of cutmemid memberid remove member combo box actid = me.cboactivityname.column(0) 'store actid activity name combo box ' build delete query activity , member strqname = "delete [tblactivityroster] ([activityid] = " & actid & ") , ([memberid] = " & cutmemid & ");" ' delete matching records db.execute strqname, dbseechanges + dbfailonerror me.qactivitymembership_subform.form.requery set db = nothing end sub
much more straightforward.
Comments
Post a Comment