Using a Defined Variable from a form in Rs.Filter

Results 1 to 2 of 2

Thread: Using a Defined Variable from a form in Rs.Filter

  1. #1
    ceejay Guest

    Default Using a Defined Variable from a form in Rs.Filter

    Can you plug in a variable read from a form into an "Rs.Filter" statement? If so, I am drawing a blank. With this code I get an error message referring to out of range, argument conflict, etc. Seems there needs to be some punctuation or bracketing around the variable, but nothing seems to work. Here&#039s the little code snippet.<BR>&#060;%<BR>&#039setting variables<BR>Dim Rs, data_source, Emp_ID<BR>Emp_ID=request.form("NoEmp")<BR>New_Addr ess=request.form("email")<BR>data_source="DSN=ati-sky;Driver{Microsoft Access Driver(*.mdb)}"<BR><BR>&#039creating recordset object and opening the database<BR>Set Rs=Server.CreateObject("ADODB.Recordset")<BR><BR>& #039Open the table<BR>rs.Open "tblTestEmail", data_source, 1, 2, adCmdTableDirect<BR><BR>&#039filtering records to get only records where the NoEmp=form&#039s NoEmp<BR>rs.Filter="NoEmp = Emp_ID"<BR><BR>&#039now updating the record<BR>rs("email")=New_Address<BR>rs.Update<BR> <BR>&#039finish<BR>rs.Close<BR>Set Rs=nothing<BR>%&#062;<BR>

  2. #2 Guest

    Default RE: Using a Defined Variable from a form in Rs.Fil

    &nbsp;&nbsp;&nbsp;&nbsp;&#060;%rs.Filter="NoEmp = Emp_ID" %&#062;<BR>should be <BR>&nbsp;&nbsp;&nbsp;&nbsp;&#060;%rs.Filter="NoEm p = " & Emp_ID &#039 if Emp_ID is numeric%&#062;<BR>or<BR>&nbsp;&nbsp;&nbsp;&nbsp;&# 060;%rs.Filter="NoEmp = &#039" & Emp_ID & "&#039" &#039 if Emp_ID is text%&#062;<BR><BR>However, I see very little value in applying a filter after opening the recordset. Why not just incorporate the filter into the query string. This would be more efficient, because the way you are doing it you waste resources by openning the whole recordset when you only need the filtered recordset.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts