MarkItZero Posted April 28, 2003 Posted April 28, 2003 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 If NameIsUnique () = True Then UpdateRecordSet() MsgBox("Progress Saved") Else MsgBox("SalesName must be Unique") End If Any suggestions? Thanks! Quote
Moderators Robby Posted April 28, 2003 Moderators Posted April 28, 2003 In the function NameIsUnique check if Salesname exists, if it does then return false else true. "Select Salesname From SalesmanTable Where Salesname = '" & sName & "'" Quote Visit...Bassic Software
APaule Posted May 1, 2003 Posted May 1, 2003 Maybe you like this one: It' just slightly different from what Robby suggested, but I think it's a bit more elegant. "Select count(*) From SalesmanTable Where Salesname = '" & sName & "'" Let's 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.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.