none
Check user input to PK in database? RRS feed

  • Question

  • I was looking through the forums and it seems the sql EXIST statement may be what I need, but:

    I have a "User ID" field on a webform and I want to make sure the user enters a valid ID. As of right now I have a slect statement that looks for the ID entered and returns slected info from the table if the ID is found.

    so I have something similar to:

    Select empName, empEmail from employees where me.txtempID = empid  (txtempID being a user input on the form)

    I then asign the empname and empEmail to strings to use later.

    At this point the program reads all of the user input and inserts it into an email msg body. I take the empEmail and attach it to  the "from" field.

    The problem lies where if the user enters the wrong ID, the program will stop working and the user has to redo it all. This is because empname and empemail returns nothing, therefore the "From" section of the email is blank, thus causing the program to halt.

    I am looking for a way to verify that the entered id exist in the database (maybe at the time the Me.txtempID loses focus); if the id exist, then they can go onto entering other information, if it does not, the program will alert the user.

    I would love to post what code I have entered, but I somehow disabled my remote software of the computer the program runs off of. Hopefully from what I said, you can provide some insight, even if a little.

    Thanks
    Friday, November 13, 2009 2:49 AM

Answers

  • EXIST statement would work in your scenario but keep in mind it does not return the actual record if it exists, which means you need to make two calls to a database if you need to check and return. You could use your existing code and check if result from SELECT statement returns the row or not, and if not show some sort of message to the user.
    Val Mazur (MVP) http://www.xporttools.net
    • Marked as answer by Yichun_Feng Thursday, November 19, 2009 2:32 AM
    Friday, November 13, 2009 11:32 AM
    Moderator