Results 1 to 3 of 3

Thread: About duplicate values

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    15

    Unhappy About duplicate values

    Hi Guys,

    I want to insert unique values and i am not using any primary key to my table.Before inserting my code it should check that it is inserting unique values and if it find any duplicate values then it should give me a message that like customer name already exists.
    I want it without using primary key in my table.

    Can any one help ......

    Thanks in advance

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    This should work good for you:

    VB Code:
    1. SQL = "Select * from Customers where UserID='" & UserID & "'"
    2.  
    3. 'recordset stuff here
    4.  
    5. If not rs.eof AND not rs.BOF then
    6.   'creation stuff
    7. else
    8.   msgbox "Create", vbexclamation, "UserID alreayd taken"
    9. end if
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Or this...

    Code:
    sql = "SELECT MAX(UserId) As 'max' FROM Customers"
    
    if(IsNull(sql("max"))) then
       nextid = 1000   'default value if no userid exists
    else
      nextid = sql("max") + 1
    end if
    
    "INSERT INTO Customers VALUES('" & nextid & "', '" & etc... & "')"
    This is of course assuming that you are wanting some unique identifier for your records...
    Last edited by Memnoch1207; Dec 2nd, 2002 at 04:10 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width