access vba - In VBA, how to convert filter to sql string where clause -
has got better way this? want users able filter set of records, , use sql statement filtered records.
my code @ moment looks following, , works. wonder if there better (or other?) way achieve avoid clunky replace statement? wondered if using recordset instead, unless i'm missing something, there's no way set operations on recordset, i'd have loop through records individually that.
any other suggestions?
dim db database dim frm form dim sqlcmd string dim filter string set db = currentdb set frm = forms("frmreplen").controls("frmreplensheet").form filter = replace(frm.filter, "[frmreplensheet].", "") sqlcmd = "update tblrcmdatasheetextract " & _ "set completed = 1 " & _ "where " & filter db.execute sqlcmd
the thing shorten procedure. this:
currentdb.execute "update tblrcmdatasheetextract set completed = 1 " & replace(forms!frmreplen!frmreplensheet.form.filter, "[frmreplensheet].", "")
or when you're running within frmreplen use
currentdb.execute "update tblrcmdatasheetextract set completed = 1 " & replace(me.frmreplensheet.form.filter, "[frmreplensheet].", "")
or within subform "frmreplensheet":
currentdb.execute "update tblrcmdatasheetextract set completed = 1 " & replace(me.form.filter, "[frmreplensheet].", "")
that puts whole procedure 1 single command. it's if better readability or shorter procedures.
Comments
Post a Comment