tags:

views:

31

answers:

1

I am very new to MS Access. I have created a database My_database.mdb with a form that displays some fields. The primary key is a field named Ticket.

When I hit the "Search" button, I want to take the numerical value 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.

What code should be in the Command_Click function?

A: 

At first blush, seems this would do the trick:

(I'm assumming "Ticket" is a numeric data type)

If Not IsNull(Dlookup("[Ticket]", "[My Table]", "[Ticket] = " & [Ticket].Value)) Then
   'It found the record, so go do something...
   Msgbox "Woo Hoo...I found it!"
Else
   'Didn't find anything, so do something else...
   Msgbox "Nope.  Nada.  Nothing."
End if

Replace the above with your table and field reference as applicable.

Jim Parker