Search, if no record - pop-up

adams.bria

Registered User.
Local time
Today, 09:05
Joined
Apr 28, 2010
Messages
41
So I have a search function that work great. However, now if my search returns no results, I would like to have a pop-up that tells the user no results were found. (Ideally I would like to from the pop-up to ask them if they want to enter the user, but I don't think that is possible) Here is my code, anyone have any ideas on where to stick an if no results logic?

Thanks in advance.


Code:
Private Sub cmdGo_Click()
On Error GoTo cmdGo_Click_Err

    If (Eval("[Forms]![frmClient_Center]![searchbox] Is Null")) Then
        ' Clear Filter when search box empty
        DoCmd.RunCommand acCmdRemoveFilterSort
        DoCmd.SetProperty "cmdShowAll", acPropertyEnabled, "0"
        End
    End If
    ' Handle "'s in search
    TempVars.Add "strSearch", Replace(Forms!frmClient_Center!searchbox, """", """""")
    ' Build the Filter
    TempVars.Add "strFilter", "([client_ID] Like "" * " & [TempVars]![strSearch] & " * "" )"
    TempVars.Add "strFilter", TempVars!strFilter & " OR ([ssn] Like "" * " & [TempVars]![strSearch] & " * "" )"
    DoCmd.ApplyFilter "", TempVars!strFilter, ""
    TempVars.Remove "strFilter"
    TempVars.Remove "strSearch"
    DoCmd.SetProperty "cmdShowAll", acPropertyEnabled, "1"


cmdGo_Click_Exit:
    Exit Sub

cmdGo_Click_Err:
    MsgBox Error$
    Resume cmdGo_Click_Exit

End Sub
 
Pseudo code:
Code:
    If Me.RecordCount = 0 Then
        If MsgBox("Nothing found! Create new item?", vbYesNo) = vbYes Then
            Me.allownew = True
            docmd.gotorecord accmdgotonew
        End If
    End If
 
(Ideally I would like to from the pop-up to ask them if they want to enter the user, but I don't think that is possible)

I keep telling people, nearly anything is possible.. just depends on how much work you want to put into it.

To create the popup to allow for user input you have a few options.

1. Very simple, no-frills option:

Code:
Dim TempUser As String

TempUser = InputBox("Search returned no results.  Please enter the user:")
'...Do something with TempUser...

This is probably your best choice. Your code can have anything you want in that argument and it returns the user's input so you can do something with it. You could easily do this in combination with the previous poster's suggestion.


2. More complicated option:

Create a new form with your message and any input you want from the user. Then call it if your search returns no records.

Code:
DoCmd.OpenForm "YourFormNameHere"

The advantage to doing it this way is that you can completely customize what the user sees and how they input that data you're looking for.
 

Users who are viewing this thread

Back
Top Bottom