I think I found a solution but here are the steps in case others have the same problem:
* First, I open an org file in Emacs.
* I then create a sparse tree using a regular expression.
* I then type M-g M-n to move to the next occurrence of my search string but it doesn't work. I get a message saying "user-error: Moved past last grep hit".
* I kill the pre-existing "*grep*" buffer in Emacs.
* I then try M-g M-n again and it works.
Writing out these steps got me thinking that there might be an option in compilation mode to switch buffers when finding next error. I looked in the
compilation mode section of the Emacs manual and found
next-error-select-buffer that switches buffers when searching for errors. I also just realized that you mentioned
next-error-find-buffer-function configuration variable in an earlier post. I'll try that as well.
You can consider my question answered. Thanks for the help.