p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   Checking to see if record exists (http://p2p.wrox.com/showthread.php?t=39319)

EmmaGale March 3rd, 2006 12:42 PM

Checking to see if record exists
Dreamweaver - ASP\Javascript - Access

Can someone please help me with a method for checking whether a record exists.

I have a table for entering pateients details and saving these to a table in an access databse. I am trying to work out the best way for the user entering the details. We cannot have duplicate patients records. Should provide a page for entering the hospital number which will then search the database and return a record if it exists or a blank form if it doesnt?

Can someone help me with the method and the code to support it.

Kind regards

adam_kahtava March 3rd, 2006 08:27 PM

How to find out if a record already exists in a database, If it doesn't Insert A New Record: http://www.dmxzone.com/ShowDetail.asp?NewsId=4615

Here's a quick example from the link above:

  Dim strSQL
  strSQL = "SELECT * FROM MyTable WHERE username = '" & _
            Request.Form("username") & "'"
  Set rs = db.Execute()

  If rs.EOF Then
    'Record does not exist
    Response.Write "Record exists"
  End If

- A.Kahtava

mat41 March 5th, 2006 07:02 PM

This will work if ALL the usernames are unique. IMO a bad example unless indeed you are using code to enforce unique user names when a user account is created.

Are you? If so the code above will work for you. If not Im sure not many people have the same email address. This is an example of a unique field that can be used.

Wind is your friend

EmmaGale March 10th, 2006 10:08 AM

Hi there thank you for your replies.

I was intending to use the patient nubmer as this is a unique field.

In terms of the code, how can i ask it to other things when it has searched the database?

For instance:

If rs.EOF Then
    Go to the data entry page
    Show the record that exists already
End If

Kind regards

adam_kahtava March 10th, 2006 10:02 PM

Replace "Go to the data entry page" with:

response.redirect "YourDataEntryPage.asp"

Everything You Need to Know About Response.Redirect: http://pubs.logicalexpressions.com/P...cle.asp?ID=214

- A.Kahtava

EmmaGale March 13th, 2006 12:40 PM

Thank you for the link - I am still not sure where I would put this code within the page. This is the main form below.

Kind regards

    <h2>Please enter hospital number:</h2>
     <form action=".asp" method="get" name="search" id="search">
        <div align="center"><br>
            <input name="hospitalNumber" type="text" id="hospitalNumber">
        <input name="search" type="submit" id="search" value="Enter">

adam_kahtava March 14th, 2006 02:39 AM

The <% %> delimiters mark the enclosed code as script code.
You can put this code in your HTML file.

Try it, put the following in your HTML code:
<% response.write "Hello World" %>

Here's a link to a good ASP Tutorial: http://www.w3schools.com/asp/default.asp

- A.Kahtava

All times are GMT -4. The time now is 04:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.