Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...