Hi all, I have 5 textbox that link to a search button on my form, and the code works fine when i fill up all 5 textbox with PO number and click search it will show data that belong to the 5 PO number that i keyed in.
However, i do face issue when i did not fill up all the 5 textbox. For example; if i just fill up 3 textbox with PO number and leave the remaining two blank and click search, the listbox will not show just the 3 PO number that i keyed in. How can i fix that?
Below is my code:
However, i do face issue when i did not fill up all the 5 textbox. For example; if i just fill up 3 textbox with PO number and leave the remaining two blank and click search, the listbox will not show just the 3 PO number that i keyed in. How can i fix that?
Below is my code:
Code:
Private Sub txtSearch_Click()
'declare variable
Dim sql As String
'Determine and return the number of records in UnmatchFabricPOqry
If DCount("*", "UnmatchNewFabricPOQry", "PO like '*" & Me.txtKeyword & "*'") & _
("PO like '*" & Me.txtKeyword1 & "*'") & _
("PO like '*" & Me.txtkeyword2 & "*'") & _
("PO like '*" & Me.txtkeyword3 & "*'") & _
("PO like '*" & Me.txtkeyword4 & "*'") = 0 Then
'Error message will be display if PO number is not found
MsgBox "No record found,check your PO again!"
Else
sql = "SELECT UnmatchNewFabricPOQry.PO, UnmatchNewFabricPOQry.[Style NO], UnmatchNewFabricPOQry.[GL Lot], " & _
"UnmatchNewFabricPOQry.Date, UnmatchNewFabricPOQry.Description2, UnmatchNewFabricPOQry.[Fabric Cuttable Width], " & _
"UnmatchNewFabricPOQry.Color, UnmatchNewFabricPOQry.[Our Qty], UnmatchNewFabricPOQry.[Supplier Qty]," & _
"UnmatchNewFabricPOQry.GSMBeforeWash, UnmatchNewFabricPOQry.[GMS Per SqYD], UnmatchNewFabricPOQry.Remark, " & _
"UnmatchNewFabricPOQry.[Fabric Weight], UnmatchNewFabricPOQry.[Unit Price], " & _
"UnmatchNewFabricPOQry.[Garment Delivery Date], UnmatchNewFabricPOQry.Line, UnmatchNewFabricPOQry.ShipName, " & _
"UnmatchNewFabricPOQry.POStatus, UnmatchNewFabricPOQry.[PO Amend No], UnmatchNewFabricPOQry.GSMAfterWash " & _
"FROM UnmatchNewFabricPOQry WHERE PO LIKE '*" & Me.txtKeyword & "*' or PO like '*" & Me.txtKeyword1 & "*' or PO like '*" & Me.txtkeyword2 & "*' or PO like '*" & Me.txtkeyword3 & "*' or PO like '*" & Me.txtkeyword4 & "*';"
Me.Lst_PO.RowSource = sql
Me.Lst_PO.Requery
End If
End Sub