Results 1 to 4 of 4
  1. #1
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76

    How to make cursor reappear in search bar after reset?

    Hi everyone

    Click image for larger version. 

Name:	agencysearchformview.PNG 
Views:	8 
Size:	13.6 KB 
ID:	30276

    Here, I have a datasheet in split form view and and a search bar that filters the datasheet based on what the user types in. Everything works fine except for one small thing. Whenever the user hits Reset the cursor appears in the agency textbox when it should reappear in the search bar textbox as seen here:

    Click image for larger version. 

Name:	postresetclick.PNG 
Views:	7 
Size:	15.6 KB 
ID:	30277

    This may present annoyances from a user perspective as they may ending up typing into this textbox when they meant to be typing into the search bar.


    Here is the vba for the reset button:


    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub cmdReset_Click()
    Me.txtSearch = ""
        Me.SrchText = ""
        Me.txtSearch.SetFocus
        DoCmd.Requery
    End Sub
    
    
    
    Private Sub Form_Load()
    DoCmd.GoToRecord , , acNewRec
    End Sub
    
    
    
    Private Sub SrchText_AfterUpdate()
    Me.SrchText.Requery
    End Sub
    
    
    Private Sub txtSearch_Change()
    'Create a string (text) variable
    
    
        Dim vSearchString As String
        vSearchString = txtSearch.Text
        SrchText.Value = vSearchString
        If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
            Exit Sub
            End If
        'Me.SearchResults = Me.SearchResults.ItemData(1)
    
        'Me.SearchResults.SetFocus
        DoCmd.Requery
        Me.txtSearch.SetFocus
        If Not IsNull(Len(Me.txtSearch)) Then
            Me.txtSearch.SelStart = Len(Me.txtSearch)
            End If
    End Sub



    I should mention that, whenever I remove the single quotes on lines:
    Code:
    'Me.SearchResults = Me.SearchResults.ItemData(1)
    
    'Me.SearchResults.SetFocus



    I get an Compile Error:

    Method or data member not found


    Also, here is the SQL in the query:


    Code:
    SELECT AgencyINFO.Agency, AgencyINFO.Subsidary, AgencyINFO.ProgramCode, AgencyINFO.ProgramNotes, AgencyINFO.Address, AgencyINFO.City, AgencyINFO.Prov, AgencyINFO.PostalCode, AgencyINFO.FirstName, AgencyINFO.LastName, AgencyINFO.ContactNameNotes, AgencyINFO.OriginalEmail, AgencyINFO.newPhoneNumber, AgencyINFO.newPhoneNumberNotes, AgencyINFO.AAStartDate, AgencyINFO.AAFinalDate, AgencyINFO.InsuranceExpiryDate, AgencyINFO.InsuranceExpiryComments, AgencyINFO.WSIBYesNo, AgencyINFO.WSIBNotes
    FROM AgencyINFO
    WHERE (((AgencyINFO.Agency) Like "*" & Forms!frmNewAgencySearch!SrchText & "*")) Or (((AgencyINFO.Subsidary) Like "*" & Forms!frmNewAgencySearch!SrchText & "*")) Or (((AgencyINFO.ProgramCode) Like "*" & Forms!frmNewAgencySearch!SrchText & "*")) Or (((AgencyINFO.FirstName) Like "*" & Forms!frmNewAgencySearch!SrchText & "*")) Or (((AgencyINFO.LastName) Like "*" & Forms!frmNewAgencySearch!SrchText & "*"));



    As always, any thoughts or suggestions are welcomed and much appreciated!

    **NOTE: I tried posting this on the access-programmers.co.uk site however, the database seems to have crashed and I am unable to post there. I understand cross-posting is not appreciated but I need assistance with this and if it turns out that my original post on access-programmers is there, then feel free to delete this post. Thank you.



  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Reverse positions of these 2 lines:
    Code:
    Private Sub cmdReset_Click()
    Me.txtSearch = ""
        Me.SrchText = ""
        DoCmd.Requery
      Me.txtSearch.SetFocus
    End Sub

  3. #3
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76
    Thank you! Worked like a charm!

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Glad to help. Good luck with the rest of your project!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need to reset search form - Part 2
    By rebfein in forum Forms
    Replies: 7
    Last Post: 04-25-2017, 09:25 AM
  2. Need to reset search form.
    By rebfein in forum Forms
    Replies: 2
    Last Post: 04-19-2017, 09:39 AM
  3. Reset button vba for a File Search
    By redekopp in forum Forms
    Replies: 10
    Last Post: 11-17-2015, 02:31 PM
  4. Replies: 2
    Last Post: 03-12-2014, 01:31 AM
  5. Replies: 9
    Last Post: 12-07-2011, 04:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums