Find record problem

andrewf10

Registered User.
Local time
Today, 22:08
Joined
Mar 2, 2003
Messages
114
I have a 'cmdFind' command button which can be used to search any field, depending on which textbox the user has the focus on.

But if another object such as a command button has the focus instead and the user doesnt notice this, a message appears:

The control 'cmdFIND' the macro is attempting to search can't be searched.


This doesn't appear to have an error number so is there any way that I can check whether a textbox in general has the focus and if not, warn the user to select a textbox to search...before the Find box appears?

I've tried using a GoToControl but this obviously jumps to the same textbox every time. Also, why does the 'Replace' tab have to appear as well?

Appreciate any help as always

Thanks
 
Why not disable the cmdFind button unless the focus is set to a text box?
 
Sounds good to me.

But being a novice programmer I dont know where to start. Remember I need check whether any textbox has the focus, not just 1 or 2. Thats where I'm stuck.

Can you pleaeeeese advise?
 
By pressing the command button surely the text box is always going to lose the focus :confused:

Why not have your code behind the double-click event of the text boxes in question? Text box won't lose the focus then
 
Thanks dan-cat

Nice idea and it works beautifully but my users use double-click to select a word for copying.
 
andrewf10 said:
Thanks dan-cat

Nice idea and it works beautifully but my users use double-click to select a word for copying.

Next idea lol

How about adding a short cut menu to your form. On right-click the short cut menu is displayed with the option of finding. Still won't need to lose the focus of your text box.

Am I getting any closer? ;)
 
Here's what I've come up with. Still needs a bit more testing but looks good so far:



Private Sub FIND_Click()
On Error GoTo Err_FIND_Click

Dim ctlCurrentControl As Control

Set ctlCurrentControl = Screen.PreviousControl
If (ctlCurrentControl.ControlType <> acTextBox) And (ctlCurrentControl.ControlType <> acComboBox) Then
MsgBox "You must click a field to search"
Exit Sub
Else
Screen.PreviousControl.SetFocus
DoCmd.RunCommand acCmdFind
End If

Exit_FIND_Click:
Exit Sub

Err_FIND_Click:
MsgBox Err.Description
Resume Exit_FIND_Click

End Sub
 
Last edited:
I see where you're going with it but I like my right-click idea lol

Here's a sample of how easy it is to get the current control name just by right-clicking on it.
 

Attachments

I've finished testing my one and couldnt find any issues so I'll go with that.

Your method opens up other doors for me though so thanks!
 

Users who are viewing this thread

Back
Top Bottom