Conflict between Command Buttons

G

Guest

I have set up two command buttons on a Form (Access 2003).
One is a Find Button the other Displays a Report.

I have a simple database - One table. The Find Command Button searches all
fields in the database for the specified string.

The Report Button Displays a list of all Companies in the Database.

The Find Button works great on its own but displays an error if I select it
after I select the Report Button. the error is as follows

"A Macro set to one of the current field's properties failed because of an
error in a FindRecord action argument."

The code behind the Command Buttons is as follows:

***********
Private Sub FormSearch_Click()
On Error GoTo Err_FormSearch_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

DoCmd.FindRecord " ", acAnywhere, , acSearchAll, , acAll, True

Exit_FormSearch_Click:
Exit Sub

Err_FormSearch_Click:
MsgBox Err.Description
Resume Exit_FormSearch_Click

End Sub
Private Sub CompanyListButton_Click()
On Error GoTo Err_CompanyListButton_Click

Dim stDocName As String

stDocName = "Drug Delivery Company List"
DoCmd.OpenReport stDocName, acPreview

Exit_CompanyListButton_Click:
Exit Sub

Err_CompanyListButton_Click:
MsgBox Err.Description
Resume Exit_CompanyListButton_Click

End Sub
************

Any help would be much appreciated.

(I would also like to know how to clear the text entry field for the next
search. It currently retains the string entered for the last search).

--Niall
 
R

Rob Oldfield

I think it's going wrong because Screen.PreviousControl will be going back
to the report button instead of where you want it to go. The code of the
search sub is a little bit out. Try replacing:

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
DoCmd.FindRecord " ", acAnywhere, , acSearchAll, , acAll, True

with

me.anyofyourcontrols.SetFocus
DoCmd.FindRecord " ", acAnywhere, , acSearchAll, , acAll, True
 

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