Results 1 to 8 of 8

Thread: Check if Record exists in Access Table

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Stourbridge, England, UK
    Posts
    171

    Check if Record exists in Access Table

    Hello,

    I'm using Access 2000 and VB6.

    I need to do a search to check if a record exists in a table, if it does I then need to display a message saying so.

    The record being searched for is a Number in a field named "OurRef" in a table named "RecordInUse".

    Any ideas because I think I am missing the obvious sollution.

    Thanks,
    SKM

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Check if Record exists in Access Table

    Run a query against the table to see how many records have the value you are searcing for. If the answer is zero, then the value doesn't exist.
    Code:
    SELECT Count(*) FROM RecordInUse WHERE OurRef = ValueToSearchFor
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Check if Record exists in Access Table

    Do a SELECT OurRef FROM RecordInUse WHERE OurRef = Value_To_Look_For

    Create a recordset

    If the recordset is empty, it doesn't exist. If the recordset is not empty, it does.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Check if Record exists in Access Table

    You say tomato, I say...
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Check if Record exists in Access Table

    Quote Originally Posted by DKenny
    You say tomato, I say...
    ...faster.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Stourbridge, England, UK
    Posts
    171

    Re: Check if Record exists in Access Table

    Hi,

    How do I find out the value of the Recordset or if the recordset is empty.

    Thanks,
    SKM

  7. #7
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: Check if Record exists in Access Table

    VB Code:
    1. msgbox ObjRS("XYZ")       'Displays the value in the XYZ column(of current row)
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Check if Record exists in Access Table

    Something like...

    VB Code:
    1. Dim adoRecordset As ADODB.Recordset
    2. Set adoRecordset = New ADODB.Recordset
    3. With adoRecordset
    4.     .Open
    5.     If Not (.EOF And .BOF) Then
    6.         MsgBox "There is record!"
    7.     Else
    8.         MsgBox "There is no record!"
    9.     End If
    10.     .Close
    11. End With
    12. Set adoRecordset = Nothing
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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