Private Sub btnSearch_Click()
Dim sql As String
Dim str As String
Dim str1 As String
Dim str2 As String
Dim strDate As String
sql = "SELECT DocumentNumber, TranType, TranDate FROM tblTranTypes INNER JOIN tblTransactions ON tblTranTypes.TranTypePK = tblTransactions.TranTypeFK WHERE DocumentNumber='" & Me.txtSearch & "'" 'LIKE '*" & Me.txtSearch.Value & "*'"
str = "SELECT DocumentNumber, TranType, TranTypeFK, TranDate FROM tblTranTypes INNER JOIN tblTransactions ON tblTranTypes.TranTypePK = tblTransactions.TranTypeFK WHERE TranTypeFK=" & Me.cboSearch 'LIKE '*" & Me.cboSearch.Value & "*'"
str1 = "SELECT DocumentNumber, TranDate, VendorsFK, CompanyName, CompanyNameArabic FROM tblVendors INNER JOIN tblTransactions ON tblVendors.VendorsPK = tblTransactions.VendorsFK WHERE VendorsFK=" & Me.cboSearch 'LIKE '*" & Me.cboSearch.Value & "*'"
strDate = "SELECT DocumentNumber, TranDate, TranType, EntityName FROM tblEntities RIGHT JOIN (tblTranTypes INNER JOIN tblTransactions ON tblTranTypes.TranTypePK = tblTransactions.TranTypeFK) ON tblEntities.EntityPK = tblTransactions.EntityFK WHERE TranDate Between #" & Me.StartDate & "# And #" & Me.EndDate & "#"
str2 = "SELECT tblTransactions.DocumentNumber, tblTransactions.TranDate, tblEntities.EntityName, tblEntities.EntityNameArabic, tblTranTypes.TranType, tblTranTypes.TranTypeArabic FROM tblTranTypes INNER JOIN (tblEntities RIGHT JOIN tblTransactions ON tblEntities.EntityPK = tblTransactions.EntityFK) ON tblTranTypes.TranTypePK = tblTransactions.TranTypeFK;"
If Not IsNull(Me.txtSearch) Then
Me.Searchlistbox1.RowSource = sql
Me.Searchlistbox1.ColumnCount = 3
Me.Searchlistbox1.ColumnWidths = "75px;110px;110px"
ElseIf Me.SearchFrame.Value = 1 And Not IsNull(Me.cboSearch) Then
Me.Searchlistbox1.RowSource = str
Me.Searchlistbox1.ColumnCount = 4
Me.Searchlistbox1.ColumnWidths = "75px;110px;0px;110px"
ElseIf Me.SearchFrame.Value = 2 And Not IsNull(Me.cboSearch) Then
Me.Searchlistbox1.RowSource = str1
Me.Searchlistbox1.ColumnCount = 5
Me.Searchlistbox1.ColumnWidths = "75px;110px;110px;110px;110px"
ElseIf Not IsNull(Me.StartDate And Me.EndDate) Then
Me.Searchlistbox1.RowSource = strDate
Me.Searchlistbox1.ColumnCount = 4
Me.Searchlistbox1.ColumnWidths = "75px;110px;110px;110px"
ElseIf Me.SearchFrame.Value = 3 And Not IsNull(Me.cboSearch) Then
Me.Searchlistbox1.RowSource = str2
Me.Searchlistbox1.ColumnCount = 6
Me.Searchlistbox1.ColumnWidths = "75px;110px;110px;110px;110px;110px"
Else
MsgBox "Cannot search blank", vbOKOnly
Me.txtSearch.SetFocus
End If
End Sub
Private Sub Form_Load()
Me.SearchFrame.DefaultValue = False
End Sub
Private Sub SearchFrame_AfterUpdate()
If SearchFrame.Value = 1 Then
cboSearch.RowSource = "SELECT DISTINCT TranTypeFK, TranType FROM tblTranTypes INNER JOIN tblTransactions ON tblTranTypes.TranTypePK = tblTransactions.TranTypeFK;"
cboSearch.ColumnCount = 2
cboSearch.ColumnWidths = "0;1cm"
ElseIf Me.SearchFrame.Value = 2 Then
cboSearch.RowSource = "SELECT DISTINCT VendorsFK, CompanyName, CompanyNameArabic FROM tblVendors INNER JOIN tblTransactions ON tblVendors.VendorsPK = tblTransactions.VendorsFK;"
cboSearch.ColumnCount = 3
cboSearch.ColumnWidths = "0;1cm;0"
ElseIf Me.SearchFrame.Value = 3 Then
cboSearch.RowSource = "SELECT DISTINCT EntityFK, EntityName, EntityNameArabic FROM tblEntities INNER JOIN tblTransactions ON tblEntities.EntityPK = tblTransactions.EntityFK;"
cboSearch.ColumnCount = 3
cboSearch.ColumnWidths = "0;1cm;0"
End If
Me.SearchFrame.Requery
End Sub