Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Posts
    1

    Unanswered: Popup if serialnumber already in table.

    I have registration form, that you write serial number and so on.
    But i will prevent the user from registrate same thing twice. So if the serialnumber already in the table, then a popup message will tell them so?
    How is this possible? Use a invisible button that activate when they pusb enter.
    Dlookup?
    Help me

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    In the past I've used a recordset. Basically using SQL in VBA to find out if there is a record where your criteria matches (therefore it's a duplicate)!

    Here's an example I wrote years ago that searches to see if a username is already in use or not. If you have any questions about it let me know!

    Oh and either stick it on an afterupdate event for your registration field or behind the button or whatever you use to save the record.
    Code:
        Dim db As Database
        Dim usertable As DAO.Recordset
        
        'Access the database
        Set db = CurrentDb()
        
        'Opens Users table
        Set usertable = db.OpenRecordset("TBL_Users", dbOpenDynaset)
        
        'Searches Users table for the correct user (note the use of single and double quotes)
        usertable.FindFirst "username = '" & txtUsername & "'"
        
        'Check to see if the username already exists
        If usertable.Fields("username") = txtUsername Then
            MsgBox ("The username already exists")
            Exit Sub
        End If
    George
    Home | Blog

  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    If the serial number field is defined with a unique index, the database won't allow a duplicate entry.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Much simpler, but you get the less-than-user-friendly access messages.
    George
    Home | Blog

  5. #5
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Agreed. I usually program around the Access messages, because they cause my users to much stress -- "I think I broke the database!"

    But make the field unique anyway, just to keep something from slipping through.
    Inspiration Through Fermentation

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    True again. There is always something that can (and undoubtebly will) fall through the net - no matter how good your validation is!

    Get it tight on your backend and then use your front end to validate and error handle ON TOP of your underlying rules.
    Quote Originally Posted by RedNeckGeek
    Quote Originally Posted by Users
    I think I broke the database!
    So, so, so, so true!

    EDIT: this is my 666th post?!
    George
    Home | Blog

Posting Permissions

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