Results 1 to 4 of 4
  1. #1
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40

    If value already exist or not in the table

    Awesome day to all! almost done with my system.. just one last question for now, (i hope) hehe..

    say i have a Text1 (for username) and Text2 (for emailaddress)

    if(Text1 == [username in database] AND Text2 == [eadd in database]


    {
    msgbox "Already exist"
    }
    else if(Text1 == [username in database] AND Text2 != [eadd in database]
    {
    data will be added to the table
    }
    else if(Text1 != [username in database] AND Text2 == [eadd in database]
    {
    data will be added to the table
    }
    else
    {
    data will be added to the table
    }

    that's what i want to happen, but i just don't know how to implement that in code..

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I have a tblsol with the fields E_Name and E_Address. I have used a Unbound form with two text boxes Text0 and Text2 I have used them to insert data into my tables.

    I have used a RecordSet to insert data:

    What the Code does.

    It will not let u enter data when both Name and Addess is in the table. You will get a prompt that the data already exist.

    Dim rs As DAO.Recordset
    Dim db As DAO.Database

    Dim strSQL As String

    strSQL = "Select * From tblsol Where E_Name='" & Me.Text0 & "' And E_Address='" & Me.Text2 & "'"

    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSQL)
    If rs.EOF And rs.BOF Then
    rs.AddNew
    Else
    MsgBox "Data Already Exist"
    rs.Close
    Set rs = Nothing
    Exit Sub
    End If

    rs!E_Name = Me.Text0
    rs!E_Address = Me.Text2
    rs.Update
    rs.Close
    Set rs = Nothing
    msgbox "Data Successfully entered"

    if this solves your problem mark the thread solved.

  3. #3
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40
    Hands Down dude! Thank you so much!

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    glad to help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Check if value exist in a table
    By Lucas83 in forum Programming
    Replies: 2
    Last Post: 06-02-2010, 11:42 AM
  2. Form doesn't exist
    By Back2Basics in forum Access
    Replies: 1
    Last Post: 02-01-2010, 11:39 AM
  3. Query: How many times does a value exist?
    By hognabbt in forum Queries
    Replies: 1
    Last Post: 01-10-2010, 01:33 PM
  4. Replies: 0
    Last Post: 10-19-2009, 11:11 AM
  5. Replies: 1
    Last Post: 08-22-2006, 04:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums