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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing feild in db before adding new

Status
Not open for further replies.

rjkealey

Programmer
Feb 14, 2003
84
0
0
US
I am trying to compare a field in the db before it will allow a new record to be added

I need to check fldParcelId ( from form) and compare it to fldParcelId(db)

Can I put in my SQL to compare first?
RS.Open "Select * From tblCharlotte", MyConn, adOpenDynamic, adLockPessimistic, adCMDText

Thanks in advance
RJKealey
 
Try something like this

rs.Open "SELECT fldParcelId FROM tblCharlotte WHERE fldParcelId='"&request.form("fldParcelId")&"'

then do this

If rs.EOF then

add the new record...

else

response.write "Sorry this id is already taken"

end if

-L
 
oops i missed the quotes in the end of the SQL statement

-L
 
Code:
newVal = "some text"

sql = "SELECT * FROM myTable WHERE fieldName = '" & newVal & "'"

set rs = cn.execute(sql)
if rs.eof then
  sql = "INSERT myTable (fieldName) VALUES ('" & newVal & "')"
  cn.execute(sql)
end if

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Whew!!! I must REALLY slow....

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Thanks all
I really appreciate the quick response and help
it worked great
thanks again
RJKealey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top