Advanced Filter search Using Combo Box

M.aliwa

New member
Local time
Today, 13:18
Joined
Oct 31, 2016
Messages
4
Hi Guys
I have a small database with only three tables of Items “ItemsT”,” Products” and” Orgin”.
Main form “Search Items by combobox” contains sub_form of items table” ItemsT subform” Filtered by Three Combo Boxes
1. Cbo_ProdId (Source from Products Table).
2. Cbo_Orgin (Source from Orgin Table).
3. Cbo_thicknessId (Source by Grouping ItThickness from ItemsT Table).

Made by visual basic As Following
Function SearchCriter()
Option Compare Database
Private Sub Cbo_Orgin_AfterUpdate()
Call SearchCriter
End Sub

Private Sub Cbo_ProdId_AfterUpdate()
Call SearchCriter
End Sub

Private Sub Cbo_thicknessId_AfterUpdate()
Call SearchCriter
End Sub

Function SearchCriter()
Dim StrProdId, StrOrgin, thicknessId As String
Dim strCriteria As String

If IsNull(Me.Cbo_ProdId) Then
StrProdId = "[ItName] like '*'"
Else
StrProdId = "[ItName]= '" & Me.Cbo_ProdId & "'"
End If

If IsNull(Me.Cbo_Orgin) Then
StrOrgin = "[ItOrgin] like '*'"
Else
StrOrgin = "[ItOrgin]= '" & Me.Cbo_Orgin & "'"
End If

If IsNull(Me.Cbo_thicknessId) Then
thicknessId = "[ItThickness] like '*'"
Else
thicknessId = "[ItThickness]= " & Me.Cbo_thicknessId
End If

strCriteria = StrProdId & "And" & StrOrgin & "And" & thicknessId
task = "Select * from ItemsT where " & strCriteria
Me.ItemsT_subform.Form.RecordSource = task
Me.ItemsT_subform.Form.Requery
End Function

Private Sub cmd_Prod_Click()
Dim StrProdId, StrOrgin, thicknessId As String
Dim strCriteria As String

If IsNull(Me.Cbo_ProdId) Then
StrProdId = "[ItName] like '*'"
Else
StrProdId = "[ItName]= '" & Me.Cbo_ProdId & "'"
End If

If IsNull(Me.Cbo_Orgin) Then
StrOrgin = "[ItOrgin] like '*'"
Else
StrOrgin = "[ItOrgin]= '" & Me.Cbo_Orgin & "'"
End If

If IsNull(Me.Cbo_thicknessId) Then
thicknessId = "[ItThickness] like '*'"
Else
thicknessId = "[ItThickness]= " & Me.Cbo_thicknessId
End If

strCriteria = StrProdId & "And" & StrOrgin & "And" & thicknessId
DoCmd.OpenReport "ItemsT", acViewPreview, , strCriteria
End Sub

Need Any Code So that I can use filter like the filter in excel & access (When I search by ProdIt and if I want to search by ItOrgin not show all value in Orgin Combobox but only that Depending with Result of ProdIt.

There's a problem while uploading My Access DB But i sent it to the admin i hope he allows to perform uploading
 

Attachments

  • SearchCriter.jpg
    SearchCriter.jpg
    76.2 KB · Views: 94

Users who are viewing this thread

Back
Top Bottom