Results 1 to 4 of 4
  1. #1
    julia_877 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    4

    Search a Number in Database Field

    Hello,

    I am very new to MS Access. I have created a database "My_database.mdb" with a form that display's some fields. One of field name "Ticket" is the primary key. When I hit the "Search" button, I want to take the value (numerical) from the Ticket's text field and search for that number in database under 'Ticket' field. If the number exists, I want to execute some set of instructions, if it does not, I want to execute other set of instructions.

    Can anyone please help me with the code that I should insert in the Command_Click function?

    Thanks, CN.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You can use a DCount to test for the existence of the number. Syntax reference:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    julia_877 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    4
    That totally works man! I just had to use the Nz(DLookup(...)) to capture the null value.

    Thanks a lot!
    CN

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help. I would have used DCount, but the Nz/DLookup will also work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Creating a Search Field
    By SKUPenn in forum Programming
    Replies: 1
    Last Post: 01-28-2010, 08:39 PM
  2. Search field is not working correctly
    By jakeao in forum Programming
    Replies: 9
    Last Post: 05-18-2009, 07:47 PM
  3. Search any field and part thereof
    By Johan in forum Programming
    Replies: 0
    Last Post: 09-08-2008, 02:18 AM
  4. Search any field and part thereof
    By Johan in forum Forms
    Replies: 0
    Last Post: 09-03-2008, 08:01 AM
  5. Search All Field
    By robbiebrown34 in forum Access
    Replies: 0
    Last Post: 05-17-2007, 09:40 AM

Tags for this Thread

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