andrewraharjo
New member
- Local time
- Today, 05:04
- Joined
- Nov 2, 2015
- Messages
- 2
Folks,
I need help for implementing / new idea how to perform search in access. Here are some descriptions:
1. Goal:
Implement compound search or we can say as multiple box and one search command button. Assume there are three text boxes name txtModelNum, txtEngineer, and txtManager. Let's say the user enters the keyword into these textboxes in order to search the record.
In this form there will be subform that generated from Model Table. This model table contains more in depth information, such as name of the tools, location and etc.
The user will only input those three boxes and once he hits enter the record should show up. This record can be pulled either from the Model table or Model subform.
2. What I've done
I've created small routine / vb script from this tutorial
youtube.com/watch?v=M6XIU5_z-UU
The tutorial seems give better description for what I'm trying to do. However I encountered error while run the search button.
The error I got it's from
Me.Model_search.Form.RecordSource = "SELECT * FROM Model" & BuildFilter
I've tried to use apply filter method but I can't make it better.
3. Snippet of the code
Private Sub CmdSearch_Click()
'On Error GoTo err
Me.Model_search.Form.RecordSource = "SELECT * FROM Model" & BuildFilter
Me.Model_search.Requery
Exit Sub
'err:
' MsgBox err.Description
End Sub
(General)
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
varWhere = Null
If Me.txtModel = "" Then
varWhere = varWhere & "[ModelNumber] like " & tmp & Me.txtModel & tmp & " AND "
End If
If Me.txtManager = "" Then
varWhere = varWhere & "[Manager] like " & tmp & Me.txtManager & tmp & " AND "
End If
If Me.txtEngineer = "" Then
varWhere = varWhere & "[Engineer] like " & tmp & Me.txtEngineer tmp & " AND "
End If
BuildFilter = varWhere
End Function
4. Question
Is there any better way and easier to implement search from multiple text boxes ? I'm looking for compound search implementation Ms Access example.
If this code wouldn't work, then I believe there is a better solution. Currently I'm in dead end of finding solution for this. Please let me know if you have better idea to implement this.
Any comments, review or help will be highly appreciated
Thanks,
Andy
I need help for implementing / new idea how to perform search in access. Here are some descriptions:
1. Goal:
Implement compound search or we can say as multiple box and one search command button. Assume there are three text boxes name txtModelNum, txtEngineer, and txtManager. Let's say the user enters the keyword into these textboxes in order to search the record.
In this form there will be subform that generated from Model Table. This model table contains more in depth information, such as name of the tools, location and etc.
The user will only input those three boxes and once he hits enter the record should show up. This record can be pulled either from the Model table or Model subform.
2. What I've done
I've created small routine / vb script from this tutorial
youtube.com/watch?v=M6XIU5_z-UU
The tutorial seems give better description for what I'm trying to do. However I encountered error while run the search button.
The error I got it's from
Me.Model_search.Form.RecordSource = "SELECT * FROM Model" & BuildFilter
I've tried to use apply filter method but I can't make it better.
3. Snippet of the code
Private Sub CmdSearch_Click()
'On Error GoTo err
Me.Model_search.Form.RecordSource = "SELECT * FROM Model" & BuildFilter
Me.Model_search.Requery
Exit Sub
'err:
' MsgBox err.Description
End Sub
(General)
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
varWhere = Null
If Me.txtModel = "" Then
varWhere = varWhere & "[ModelNumber] like " & tmp & Me.txtModel & tmp & " AND "
End If
If Me.txtManager = "" Then
varWhere = varWhere & "[Manager] like " & tmp & Me.txtManager & tmp & " AND "
End If
If Me.txtEngineer = "" Then
varWhere = varWhere & "[Engineer] like " & tmp & Me.txtEngineer tmp & " AND "
End If
BuildFilter = varWhere
End Function
4. Question
Is there any better way and easier to implement search from multiple text boxes ? I'm looking for compound search implementation Ms Access example.
If this code wouldn't work, then I believe there is a better solution. Currently I'm in dead end of finding solution for this. Please let me know if you have better idea to implement this.
Any comments, review or help will be highly appreciated
Thanks,
Andy