Results 1 to 6 of 6
  1. #1
    MeekoRayne is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2020
    Posts
    5

    Clear Record from an Empty Search Text Box

    Good Morning,

    I'm creating an entry form and I have a search text box to bring up a record whenever the Search button is pressed. Once you're done with the record, you have a blank Search box and it should bring up a clean, empty form when you press the Search button. However you hit the Search button on an empty Search text box and it brings up the first record of the table. What code would I have to place into the Search button that brings up a clear form when ever the Search Text Box is empty?



    This is what I have thus far.
    Click image for larger version. 

Name:	Search Box Formula 2.jpg 
Views:	19 
Size:	43.4 KB 
ID:	42224Click image for larger version. 

Name:	Inprocessing Form Outline 2.jpg 
Views:	20 
Size:	64.5 KB 
ID:	42225

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    ......What code would I have to place into the Search button that brings up a clear form........
    When you say "clear", do you mean a new blank record?
    Can you post the actual text of your code, so we don't have to type it all, within code tags rather than as a screen shot.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    MeekoRayne is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2020
    Posts
    5
    Quote Originally Posted by Bob Fitz View Post
    When you say "clear", do you mean a new blank record?
    Can you post the actual text of your code, so we don't have to type it all, within code tags rather than as a screen shot.

    Yes, When the Search button is pressed on an empty Search Text Box, I would like the form to be on a blank record, Instead of the first record of the database. The code for the Search button is below. Thank you.


    Private Sub SearchBtn_Click()

    Dim SQL As String



    SQL = " SELECT Inbound.[InboundID], Inbound.[Rank], Inbound.[LName], Inbound.[FName], Inbound.[CrewPos], Inbound.[RNLTD], Inbound.[Sponsor], " _
    & " Inbound.[ExpArrivalDate], Inbound.[ActArrivalDate]," _
    & " Inbound.[Email], Inbound.[PhoneNum], Inbound.[Phase], Inbound.[Notes]" _
    & " FROM Inbound" _
    & " WHERE [LName] LIKE '*" & Me.SearchBox & "*' " _
    & " OR [FName] LIKE '*" & Me.SearchBox & "*' " _
    & " ORDER BY Inbound.LName"


    Me.Form.RecordSource = SQL
    Me.Form.Requery

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Maybe:
    Code:
    Private Sub SearchBtn_Click()
    
    Dim SQL As String
    
    If Nz(Me.SearchBox,0) = 0 Then
    
      DoCmd.GoToRecord , "", acNewRec
    
    Else
    
      SQL = " SELECT Inbound.[InboundID], Inbound.[Rank], Inbound.[LName], Inbound.[FName], Inbound.[CrewPos], Inbound.[RNLTD], Inbound.[Sponsor], " _
      & " Inbound.[ExpArrivalDate], Inbound.[ActArrivalDate]," _
      & " Inbound.[Email], Inbound.[PhoneNum], Inbound.[Phase], Inbound.[Notes]" _
      & " FROM Inbound" _
      & " WHERE [LName] LIKE '*" & Me.SearchBox & "*' " _
      & " OR [FName] LIKE '*" & Me.SearchBox & "*' " _
      & " ORDER BY Inbound.LName"
    
      Me.Form.RecordSource = SQL
      Me.Form.Requery
    
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    MeekoRayne is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2020
    Posts
    5
    Well What do you know, that worked!!! Thank you very much!

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    O ye of little faith 😃
    I never had any doubts 😎
    Glad you've got it working.

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

Similar Threads

  1. Cant Clear RecordSource after Search
    By ortizimo in forum Access
    Replies: 4
    Last Post: 05-23-2019, 09:02 AM
  2. Replies: 1
    Last Post: 02-28-2018, 01:02 PM
  3. Clear Search Form
    By armyofdux in forum Forms
    Replies: 9
    Last Post: 03-03-2015, 06:24 AM
  4. Replies: 2
    Last Post: 03-12-2014, 01:31 AM
  5. Search and Clear button
    By polk383 in forum Programming
    Replies: 1
    Last Post: 08-30-2006, 08:51 AM

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