Having to click a Cmd button twice to get it to respond

E

excelnut1954

The 1st sub below performs a Find, then opens up UserForm13. The next 2
subs below it work via command buttons in UserForm13 to show the Next &
Previous records, if there are more than one found in the initial Find.


If I hit the Next button after getting to the last record, I get the
messagebox telling the user that there are no more records found, which
you can see in the sub. After I get that messagebox and click OK, if I
click the Previous button to go backwards, I have to click the Previous
button twice before it starts going back one record for each click.

If I don't click Next far enough to get the messagebox, then the
Previous button will respond Ok with one click. Only if I get to the
point where the messagebox appears.

Can anyone see where I can adjust the code so that it will go back on
the 1st click of the Previous button after getting to the point where
the messagebox comes up? Is there a line of code I should have here
after the messagebox that "activates" it to allow the Previous
button to work on the 1st click?

Thanks,
J.O.

'This 1st sub is the initial Find
Sub FindViaPOCurrent()
'This is for the PO/PL search via UserForm12. Clicking the OK button
'brings you here. If record found, it opens up UserForm13 to show
'that record. The "Find Another Record" button will also loop back
here.

Worksheets("Official List").Activate
Set rngToSearch = Sheets("Official List").Columns("J")

Set rngFound = rngToSearch.Find(What:=FindPOVal, _
LookIn:=xlValues, _
LookAt:=xlWhole)

If rngFound Is Nothing Then
MsgBox "This record was not found. Make sure you entered the
correct number. Also, check the Deleted List."
Unload UserForm12
UserForm12.Show

Else
strFirst = rngFound.Address
rngFound.Select

Unload UserForm12
UserForm13.Show

End If

End Sub

Sub FindNextViaPOCurrent()
Worksheets("Official List").Activate
Set rngFound = rngToSearch.FindNext(rngFound)
rngFound.Select
If rngFound.Address = strFirst Then
MsgBox "There are no other records with this PO/PL."

Else
Unload UserForm13
UserForm13.Show
End If

End Sub

Sub FindPreviousViaPOCurrent()

Worksheets("Official List").Activate
Set rngFound = rngToSearch.FindPrevious(rngFound)
rngFound.Select

Unload UserForm13
UserForm13.Show

End Sub
 

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