Function: Check for Unique Value

MarkItZero

Active member
Joined
Apr 10, 2003
Messages
43
Location
under the desk in my office
Hello again,

In my app, I have a form which contains a listbox with all of the SalesNames from my Access table Salesman. When you click on one of the names in the listbox, the textboxes on the form are populated with the details of the record from the Salesman table.

Salesman
SalesID: AutoNumber
SalesName: Text
Password: Text
SecurityLevel: Number

The user is able to update the values in the SalesName, Password and SecurityLevel fields through Textboxes on the form.

When the User clicks Save, the values from the textbox are inserted into the database.

What I need to do, is set up a function that checks to make sure that the value in the Salesname text box is unique. I will then call the funtion everytime the user clicks the save button

Code:
If NameIsUnique () = True Then
        UpdateRecordSet()
        MsgBox("Progress Saved")
Else
        MsgBox("SalesName  must be Unique")
End If

Any suggestions?
Thanks!
 
In the function NameIsUnique check if Salesname exists, if it does then return false else true.

"Select Salesname From SalesmanTable Where Salesname = " & sName & ""
 
Maybe you like this one:
It just slightly different from what Robby suggested, but I think its a bit more elegant.

"Select count(*) From SalesmanTable Where Salesname = " & sName & ""

Lets say this is the commandstring of a command object called cmd in your function NameIsUnique and you have also a boolean variable called bUnique.
Then you can code:

bUniqe=(CType(cmd.ExecuteScalar, Integer)=0)

E Voila....
 
Back
Top