A
Angi
This code is pretty straightforward and I've been using it for years,
but it started acting funny when I added a line.
I have a searchfrm with a Search Again btn. When the parameter prompt
comes up and I enter info, I can press the enter key and the query will
run. If I press the btn I can do it again and again. My
Exit_CmdFind_Click used to say Exit Sub, but that just brought me back
to the form. I wanted it to close the form, so I changed it to
docmd.close. Now, the form runs right the first time you open it (you
can use the enter key) but when you use the search again btn and then
press enter, the form now closes. It also closes when the cancel
button is clicked. I have the code set to only do this when the user
presses the cancel button (Err 2001), but now it's doing it all the
time. The ok is the default. Obviously because it doesn't happen when
that line isn't in there.
Can someone tell me why it's doing this or another way to close the
form if the user presses the cancel button on the parameter prompt?
Private Sub SearchAgainBtn_Click()
On Error GoTo Err_cmdFind_Click
Me.Requery
Err_cmdFind_Click:
If Err.Number = 2001 Then Resume Exit_cmdFind_Click
Exit_cmdFind_Click:
DoCmd.Close
End Sub
TIA!
but it started acting funny when I added a line.
I have a searchfrm with a Search Again btn. When the parameter prompt
comes up and I enter info, I can press the enter key and the query will
run. If I press the btn I can do it again and again. My
Exit_CmdFind_Click used to say Exit Sub, but that just brought me back
to the form. I wanted it to close the form, so I changed it to
docmd.close. Now, the form runs right the first time you open it (you
can use the enter key) but when you use the search again btn and then
press enter, the form now closes. It also closes when the cancel
button is clicked. I have the code set to only do this when the user
presses the cancel button (Err 2001), but now it's doing it all the
time. The ok is the default. Obviously because it doesn't happen when
that line isn't in there.
Can someone tell me why it's doing this or another way to close the
form if the user presses the cancel button on the parameter prompt?
Private Sub SearchAgainBtn_Click()
On Error GoTo Err_cmdFind_Click
Me.Requery
Err_cmdFind_Click:
If Err.Number = 2001 Then Resume Exit_cmdFind_Click
Exit_cmdFind_Click:
DoCmd.Close
End Sub
TIA!