DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Help Please--record finding in access db

  1. #1
    Join Date
    Feb 2007

    Arrow Help Please--record finding in access db


    i have MS access database with a "itmname" field
    and a form with a textbox and a button

    i want a code to check the database before add new record if
    name in textbox already exist in database raise a message like
    "name already exists" else add name on textbox in database.

    im begginer and please write codes in vb6

    Last edited by x-pc; 02-07-2007 at 08:49 PM.

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    Add a reference in your project (Project -> References...) to Microsoft DAO Object Library. Then do something like this:
    If Not SaveItemName(txtItemName.Text) Then
        ' Name already exists
    End If
    Function SaveItemName(ByVal ItemName As String) As Boolean
        Dim db As Database
        Dim rs As Recordset
        Dim result As Boolean
        Set db = OpenDatabase("d:\path\filename.mdb")
        ' Get number of records whose itmname field
        ' matches ItemName parameter value
        Set rs = db.OpenRecordset("SELECT COUNT(*) FROM TableName WHERE itmname = '" & ItemName & "'")
        ' If count > 0, name already exists
        If rs(0) > 0 Then
            result = False
            ' If name not found, insert new ItemName
            db.Execute "INSERT INTO TableName (itmname) VALUES ('" & ItemName & "')"
            result = True
        End If
        ' Clean up
        ' Return success or failure
        SaveItemName = result
    End Function
    Last edited by Phil Weber; 02-07-2007 at 09:07 PM.
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. trsafering access record in sql data base...
    By luca90 in forum Database
    Replies: 1
    Last Post: 01-14-2007, 08:03 AM
  2. Replies: 8
    Last Post: 03-08-2003, 07:25 PM
  3. VirtualQueryEx
    By MacDeath in forum VB Classic
    Replies: 2
    Last Post: 02-14-2001, 06:44 AM
  4. Add new record to Access from VB.
    By Susann in forum VB Classic
    Replies: 3
    Last Post: 05-15-2000, 01:47 PM
  5. Current record position in Access
    By PFLEGER in forum VB Classic
    Replies: 1
    Last Post: 05-10-2000, 05:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center