Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a Delete Query 1

Status
Not open for further replies.

ACCESSDUMMY

Programmer
Oct 22, 2003
33
US
I want to create a Delete query based on a parameter that the user enters. How can I make the query not execute if the user doesn't enter the criteria or enters invalid data for the parameter?

I know that the following code will select all values if no value is entered, but I don't want the user to delete all the records if left blank.

[Enter Value] Or [Enter Value] Is Null

Does anyone has some input on this for me?
Thanks,
Amy
 
Run the procedure from a form. Place a field on the form for entry of the parameter. The following assumes a form named MyForm with a field MyParameter. In the afterupdate event procedure for the field place code something like this:

If Not IsNull(Me!MyParameter) or Me!MyParameter <> &quot;&quot; then
DoCmd.OpenQuery &quot;MyQuery&quot;
else
Msgbox &quot;Enter a value dummy!&quot;
End if

On the criteria line of the MyQuery query enter the following syntax:

Forms!MyForm!MyParameter

When the query runs it will look in the MyParameter field of the MyForm form for the value to use as criteria.

When the user enters a value in the MyParameter field the event procedure will test for a blank value. If it's blank the user gets a message saying enter a value. If it's not blank then the query will run using the value that the user has entered.

Hope this helps.

AvGuy
 
Thanks for the code... I'll give it a try in a minute. I may have to edit out the word &quot;dummy&quot;, as it might cause me to lose my job. :)
Thanks again!
Amy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top