Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close the Close and Find dialog box

Status
Not open for further replies.

jimmypur

IS-IT--Management
Jul 22, 2004
17
FR
Hi

I have used some code, found here I believe, to create a Find dialog box or input box to make finding a record as quickly as possible when a client telephones or if I need to find a particular record quickly

The code is

Private Sub cmdFind_Click()
'Search for Specific LastName in the "Last Name" field
On Error GoTo Err_Find_Click
Dim strLen, i As Integer
Dim strTempName, strSearchName As String

strLen = Len(strSearchName)

DoCmd.GoToControl "LastName"
strSearchName = InputBox("Enter any part of the last name.", "Look Up Last Name")
DoCmd.FindRecord strSearchName, acAnywhere, , acSearchAll, , acCurrent, True
DoCmd.RunCommand acCmdFind

Exit_Find_Click:
Exit Sub

Err_Find_Click:
[LastName].SetFocus
'MsgBox "Cancelled"
'Resume Exit_Find_Click
End Sub

This works quite nicely but:

1. When it has found the first record it closes the inbox and leaves the MS Access Find and Replace dialog box on the screen.

Does anybody know how I can prevent this? ie when the search has found the first record it closes the input box and box and sets focus on a particular field Notes: this is a simple text box for "scribbling" notes down on to quickly say during a phone call.

Thanks

Jpur
 
You may take a look at the RecordsetClone, FindFirst, NoMatch, Bookmark and SetFocus methods/properties of the Form, Recordset and TextBox objects.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You may have figured this out by now, but you can drop the
"DoCmd.RunCommand acCmdFind"
line, and that solves the probelm.

Thanks for posting the code anyway, I was able to modify it for my needs - a Find dialog box that can be called from any form:

In a public module
Code:
Public Sub MultiFind(InputText As String, ControlToSearch As Control)
'On Error GoTo HandleErr
    'Search for things passed from the calling module

    Dim strSearchItem As String
    
    ControlToSearch.SetFocus
    
    strSearchItem = InputBox("Find somthing...", InputText)
    DoCmd.FindRecord strSearchItem, acAnywhere, , acSearchAll, , acCurrent, True
    
ExitHere:
    Exit Sub
HandleErr:
    Select Case Err.Number
        Case 2142 'Nothing entered in find box
            Exit Sub
        Case Else
            'Cope with other errors here...
    End Select
' End Error handling block.
End Sub

You can call it from any form with something like the following attached to a button:
Code:
Private Sub ButFindSiteCODE_Click()
'On Error GoTo Err_ButFindSiteCODE_Click

    Dim InputText As String
    Dim ControlToSearch As Control
    Set ControlToSearch = Forms![F2000SiteDetails]![BoxSiteCODE]
    InputText = "Please enter a site code:"
    
    Call MultiFind(InputText, ControlToSearch)

Exit_ButFindSiteCODE_Click:
    Exit Sub
End Sub

Hope that's useful to someone...

Phil

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top