Option Compare Database
Option Explicit
Private Function basOrderby(strKey1 As String, strKey2 As String) As Integer
Dim strSQL As String
'Set row source for list box
If (Len(strKey1) > 0 And Len(strKey2) > 0) Then
strSQL = "SELECT NameItem, [strSalespersonID]"
strSQL = strSQL & " FROM data "
strSQL = strSQL & " WHERE NameItem LIKE " & "'*" & strKey1 & "*'" & " OR Model LIKE " & "'*" & strKey2 & "*'"
strSQL = strSQL & " ORDER BY NameItem;"
ElseIf (Len(strKey1) > 0 And Len(strKey2) <= 0) Then
strSQL = "SELECT NameItem, [NameItem]"
strSQL = strSQL & " FROM data "
strSQL = strSQL & " WHERE NameItem LIKE " & "'*" & strKey1 & "*'"
strSQL = strSQL & " ORDER BY NameItem;"
ElseIf (Len(strKey1) <= 0 And Len(strKey2) > 0) Then
strSQL = "SELECT NameItem, [NameItem] "
strSQL = strSQL & " FROM data "
strSQL = strSQL & " WHERE Model LIKE " & "'*" & strKey2 & "*'"
strSQL = strSQL & " ORDER BY NameItem;"
End If
Me!lstSearch.RowSource = strSQL
Me!lstSearch.Requery
End Function
Private Sub cmdSearch_Click()
Dim response As Integer
If IsNull(Forms![frmSearch]!txtCode) And IsNull(Forms![frmSearch]!txtName) Then
MsgBox "?????????????????????????????????", vbCritical + vbOKCancel, "???????"
ElseIf IsNull(Forms![frmSearch]!txtCode) Then
response = basOrderby("", Trim(Forms![frmSearch]!txtName))
Private Sub Form_Open(Cancel As Integer)
txtCode.SetFocus
End Sub
Private Sub lstSearch_AfterUpdate()
'Once a record is selected in the list, enable the showRecord button
ShowRecord.Enabled = True
End Sub
Private Sub lstSearch_DblClick(Cancel As Integer)
'If the user double-clicks in the list, act as though
'the ShowRecord button was clicked
If Not IsNull(lstSearch) Then
ShowRecord_Click
End If
End Sub
Private Sub ShowRecord_Click()
'Find a selected record, then close the search dialog box