I am using Ms Access 2013 and the resource for the search is taken from http://www.iaccessworld.com/how-to-create-search-form/
The supplier table(tblSuppli er) with fields (SupplierID , Company , FirstName, LastName , BusinessPhone ,Address and City)
From this I have created a tabular view on a continuos form
The attachment shows the screen capture of the design.
The code is :
(1) DeSelectAll command button
(2) Command button Search
(3)Command button SelectAll
(4) Command Button ShowAll
(5) On form Load
I need help for the search query....
The supplier table(tblSuppli er) with fields (SupplierID , Company , FirstName, LastName , BusinessPhone ,Address and City)
From this I have created a tabular view on a continuos form
The attachment shows the screen capture of the design.
The code is :
(1) DeSelectAll command button
Code:
Option Compare Database Private Sub cmdDeselectAll_Click() 'Links this subroutine to the command button 'cmdDeSelectAll 'This command will uncheck all the following check boxes: 'ChkCompany 'ChkFirstName 'ChkLasName 'ChkBusinessPhone 'ChkAddress 'ChkCity Me.ChkCompany = False Me.ChkFirstName = False Me.ChkLastName = False Me.ChkBusinessPhone = False Me.ChkAddress = False Me.ChkCity = False End Sub
(2) Command button Search
Code:
Private Sub cmdsearch_Click() Dim strSearch As String 'Declare the variable strSearch as data type string Dim Search As String 'Declare the variable Search as data type string If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed" Me.txtSearch.SetFocus Else I don't know if the code is correct.... [B] strSearch = Me.txtSearch.Value 'The value from the text box txtSearh is assigned th 'the varuable strSearch Search = "SELECT * from tblSupplier where ((FirstName Like ""*" & strSearch & "*""))"[/B] End If End Sub
(3)Command button SelectAll
Code:
Private Sub cmdSelectAll_Click() 'Links this subroutine to the command button 'cmdSelectAll 'This command will check all the following check boxes: 'ChkCompany 'ChkFirstName 'ChkLasName 'ChkBusinessPhone 'ChkAddress 'ChkCity Me.ChkCompany = True Me.ChkFirstName = True Me.ChkLastName = True Me.ChkBusinessPhone = True Me.ChkAddress = True Me.ChkCity = True End Sub
(4) Command Button ShowAll
Code:
Private Sub cmdShowAll_Click() 'Links this subroutine to the command 'botton cmsShowAll Dim strSearch As String 'Declare the variable strSearch as data ' type string strSearch = "SELECT *FROM tblSupplier" 'The task value of task is obtained from ' the table tblSupplier Me.RecordSource = strSearch 'The strSearch is assigned to the current 'record source End Sub
(5) On form Load
Code:
Private Sub Form_Load()
Dim Search As String
Search = "SELECT *FROM tblSupplier WHERE(SupplierID)is null"
Me.RecordSource = Search
Me.txtSearch.SetFocus
End Sub
Private Sub txtSearch_AfterUpdate()
'Links this subroutine to the event procedure
'After the update of the textbox txtSearch
Call cmdsearch_Click
'Call the command cmdSearch on click
End Sub
Comment