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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Acess search problem

Status
Not open for further replies.

jvandel

MIS
Sep 14, 2004
5
US
Just upgraded to office 2003 on a machine. Now when I run the following code
DoCmd.FindRecord txtFindMe, , True, , True
It finds the correct record but the user must click on the form to change the value.
In 2000 and XP it let them change the value without having to click the form.
Anyone know how to fix this?
 
Wild guess - you may need to set the focus on the control that contains the text to be changed. Something like this:
Code:
Me.[!]MyControl[/!].SetFocus

You will need to change the text in red to match your control.

Hope this helps.

Tom

Born once die twice; born twice die once.
 
Thanks for the reply but that did not work. I even tried setting the focus to another control and then back to the original with no luck. Here is the code.

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "SHIPMENT", "s:\canada\Matrix Feed.xls", True
DoCmd.Requery
PO_Number.SetFocus
txtFindMe = "?"
DoCmd.FindRecord txtFindMe, , True, , True
PO_Number.SetFocus


I tried changing the default value of "?" to something else and still the same problem.

Any other suggestions.
 
How about this:
Code:
DoCmd.GoToControl "PO_Number"

By the way, I hope you don't mind my guessing since I don't have much time for testing. Hope it helps.

Tom

Born once die twice; born twice die once.
 
That didn't work either. It highlights the control the same as the others but I still can't type over unless I click on the form. It will then give me a flashing cursor
I don't mind any suggestions.
 
I think this will get you what you need - it's straight from Access help:
Code:
SelLength Property
See Also Applies To Example Specifics 
The SelLength property specifies or determines the number of characters selected in a text box or the text box portion of a combo box. The SelLength property uses an Integer in the range 0 to the total number of characters in a text box or text box portion of a combo box. 
Remarks
You can set the SelLength property by using a macro or Visual Basic.

To set or return this property for a control, the control must have the focus. To move the focus to a control, use the SetFocus method.

Setting the SelLength property to a number less than 0 produces a run-time error.

Example
The following example uses two event procedures to search for text specified by a user. The text to search is set in the form's Load event procedure. The Click event procedure for the Find button (which the user clicks to start the search) prompts the user for the text to search for and selects the text in the text box if the search is successful.

Private Sub Form_Load()
    
    Dim ctlTextToSearch As Control
    Set ctlTextToSearch = Forms!Form1!Textbox1
    
    ' SetFocus to text box.
    ctlTextToSearch.SetFocus
    ctlTextToSearch.Text = "This company places large orders twice " & _
                           "a year for garlic, oregano, chilies and cumin."
    Set ctlTextToSearch = Nothing
    
End Sub

Public Sub Find_Click()
    
    Dim strSearch As String
    Dim intWhere As Integer
    Dim ctlTextToSearch As Control
    
    ' Get search string from user.
    With Me!Textbox1
        strSearch = InputBox("Enter text to find:")
        
        ' Find string in text.
        intWhere = InStr(.Value, strSearch)
        If intWhere Then
            ' If found.
            .SetFocus
            .SelStart = intWhere - 1
            .SelLength = Len(strSearch)
        Else
            ' Notify user.
            MsgBox "String not found."
        End If
    End With
    
End Sub

Hope you can tweak as needed.

Tom

Born once die twice; born twice die once.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top