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!

Check if a input value exists

Status
Not open for further replies.

newtoitall

Technical User
Jun 16, 2005
100
GB
I have been asked to apply a simple bit of validation to an input field, but haven't got a clue.

Basically Add.asp displays the input form for info to be keyed in. It then passes values to addupdate.asp, which writes data keyed in by the user to the access database.

I need the interface to check if an invoice number inputted into the form already exists in the database. If it does then msgbox just to inform user, whether they wish to continue to save or not. The invoice number is not a primary key, just a field.

Any ideas?
 
Ok, because ASP is server side scripting you cannot use msgbox. You could so something similar using AJAX (look it up on Google), or you could simply return a message to the browser advising that it already exists.

Code:
'Use a recorset to run a SQL statement against the database.

'Then it's just some simple validation

if RS.eof then
'No record exists, continue with insert
else
'Record exists
response.write "sorry but this record already exists"
end if

Cheers

Nick
 
Since you are "new to it all" I would not recommend going into AJAX just yet.

What if, before an INSERT is done on the new value, the code first does a SELECT query with the new value specified in the WHERE clause.

Then, if the query returns anything other than zero results, print a message to that the value already exists and please try again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top