Search Form & Option Buttons

scgamecock

New member
Local time
Today, 02:44
Joined
Sep 17, 2007
Messages
8
I would like to come up with a way to have my search form use option buttons. The data in the table can either be disposed or not disposed. I would like to have two option buttons on my form (Yes & No). If option button 'Yes' is selected, then the search form will show only the data that has been disposed. If the option button 'No' is selected then the data that has not been disposed will display.

Here is the code for my search form now:

Code:
Option Compare Database
Private Sub cmdSearch_Click()
    Dim strSampleNumber As String
    Dim strSearch As String
    
'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
        Me![txtSearch].SetFocus
        
    Exit Sub
End If
'---------------------------------------------------------------
        
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
        
    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("sampleno")
    DoCmd.FindRecord Me!txtSearch
        
    sampleno.SetFocus
    strSampleNumber = sampleno.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text
        
'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control

    If strSampleNumber = strSearch Then
        MsgBox "Match Found For: " & strSearch, , "Congratulations!"
        txtSearch.SetFocus
        txtSearch = ""
        
    'If value not found sets focus back to txtSearch and shows msgbox
        Else
          MsgBox "Sample ID " & strSearch & " has not been disposed.", _
            , "Invalid Sample ID!"
            txtSearch.SetFocus
            txtSearch = ""
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom