'not found' message when opening a form

K

Karen

I have a form (frmshelflife) that uses a query (qrysearchshelflife) for its
datasource. The query gets the criteria from a dialog box. When the user
enters a code in the dialog box and clicks the 'OK' button, frmshelflife
opens and displays the code, description, and shelflife of the item. I need
to put a message box in there to tell the user if their code wasn't found.
Right now if the code isn't found, frmshelflife displays blank and the user
is stuck with this blank form that can't be closed. I would like a message
box to come up and say 'code not found' and then when the ok button is
clicked the message box closes and the dialog box is restored (it was never
closed). I don't want frmshelflife to open at all if the code isn't found.
IF I have to have it open, I want to close it when the ok button on the
message box is clicked.


I appreciate your help.

Karen
 
G

Guest

Karen,

When you say the query gets the criteria from a dialog box, do you mean an
Input Box or a form?
 
G

Guest

Ok, then in the same event and before you open your form, use the Dlookup
function to see if the code is there or not. If it is not, don't open the
form and allow the user to reenter the code or cancel.
 
K

Karen

I got this to work by using the following code as the onclick of the ok
button on my dialog box form. Thank You Klatuu!!


If DLookup("[fldcode]", "tblReagents", "[fldcode] = Forms![frm shelflife
dialog box]!Text0") Then
'open the shelflife form
DoCmd.Minimize 'to minimize the dialog box
DoCmd.OpenForm "frmshelflife", acNormal 'open the form

'if not found
Else
'display a message
MsgBox "The code you entered is not valid", vbExclamation, "Code Not
Found"

End If


Karen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top