I have a screen which is a submitting screen and a search screen at the same time and result of the search gets dispalyed in a grid.That is fine,but if I search for records (example starting with "ac")that will give me a list of records that contain those letters,that is fine.
What i have a problem with is that I clear the field criteria and start a new search but it only gets added onto what I have displayed in the grid so some records end up being dispalyed again even though they only exist once.
So when I clear the field where I enter the search criteria i would like to clear the grid as well, not having all that luck with that.
this is the code for search button,use SQLserver as a database:
Private Sub cmdSearch_Click()
Dim szQuery As String
Dim ctrlObj As Control
Dim szTemp As String
Dim nErr As Integer
Dim Handle As Integer
Dim lCount As Long
Dim szDate As String
Dim szDate1 As String
lstResults.ListItems.Clear
Handle = SessionHandle(cszSessionHandle)
If Handle < 0 Then
Call myobj.ReportError(Handle, Handle, "connecting to the required database.", App.title)
Exit Sub
End If
For Each ctrlObj In Controls
If ctrlObj.Tag <> "" Then
Select Case Left$(ctrlObj.Name, 3)
Case "txt"
If ctrlObj.Text <> "" Then
If szQuery <> "" Then
szQuery = szQuery & " AND DispatchTime IS NULL "
End If
szQuery = szQuery & Replace(ctrlObj.Tag, "%", BuildString(ctrlObj.Text, , WILD_BOTH))
End If
End Select
End If
Next
If szQuery <> "" Then
szQuery = " WHERE " & szQuery & " AND DispatchTime IS NULL"
End If
MousePointer = 11
nErr = myobj.DoQuery(Handle, "TEST", szQuery)
If myobj.ReportError(Handle, nErr, "searching the Customer details.", App.title) = True Then
MousePointer = 0
Exit Sub
End If
grdResults.Visible = False
For lCount = 0 To myobj.ListCount(Handle) - 1
szDate = myobj.List(Handle, lCount, "PrintedWhen")
If IsDate(szDate) Then
szDate = StandardDateTime(CDate(szDate))
End If
grdResults.AddItem myobj.List(Handle, lCount, "FirstBoxNbr") & vbTab & _
szDate & vbTab & _
myobj.List(Handle, lCount, "DispatchTime")
Next lCount
fraDispatchResults.Caption = "Units to be dispatched (" & CStr(grdResults.Rows - 1) & ")"
grdResults.Visible = True
grdResults.Visible = True
MousePointer = 0
End Sub
This is the clear button code:
Private Sub cmdClear_Click()
Dim ctrlObj As Control
For Each ctrlObj In Controls
If ctrlObj.Tag <> "" Then
Select Case Left$(ctrlObj.Name, 3)
Case "txt"
ctrlObj.Text = ""
End Select
End If
Next
End Sub
So how could I clear the grid, either with the clear button or to clear it when I start a new search.
Could somebody please help me with this?
regards
What i have a problem with is that I clear the field criteria and start a new search but it only gets added onto what I have displayed in the grid so some records end up being dispalyed again even though they only exist once.
So when I clear the field where I enter the search criteria i would like to clear the grid as well, not having all that luck with that.
this is the code for search button,use SQLserver as a database:
Private Sub cmdSearch_Click()
Dim szQuery As String
Dim ctrlObj As Control
Dim szTemp As String
Dim nErr As Integer
Dim Handle As Integer
Dim lCount As Long
Dim szDate As String
Dim szDate1 As String
lstResults.ListItems.Clear
Handle = SessionHandle(cszSessionHandle)
If Handle < 0 Then
Call myobj.ReportError(Handle, Handle, "connecting to the required database.", App.title)
Exit Sub
End If
For Each ctrlObj In Controls
If ctrlObj.Tag <> "" Then
Select Case Left$(ctrlObj.Name, 3)
Case "txt"
If ctrlObj.Text <> "" Then
If szQuery <> "" Then
szQuery = szQuery & " AND DispatchTime IS NULL "
End If
szQuery = szQuery & Replace(ctrlObj.Tag, "%", BuildString(ctrlObj.Text, , WILD_BOTH))
End If
End Select
End If
Next
If szQuery <> "" Then
szQuery = " WHERE " & szQuery & " AND DispatchTime IS NULL"
End If
MousePointer = 11
nErr = myobj.DoQuery(Handle, "TEST", szQuery)
If myobj.ReportError(Handle, nErr, "searching the Customer details.", App.title) = True Then
MousePointer = 0
Exit Sub
End If
grdResults.Visible = False
For lCount = 0 To myobj.ListCount(Handle) - 1
szDate = myobj.List(Handle, lCount, "PrintedWhen")
If IsDate(szDate) Then
szDate = StandardDateTime(CDate(szDate))
End If
grdResults.AddItem myobj.List(Handle, lCount, "FirstBoxNbr") & vbTab & _
szDate & vbTab & _
myobj.List(Handle, lCount, "DispatchTime")
Next lCount
fraDispatchResults.Caption = "Units to be dispatched (" & CStr(grdResults.Rows - 1) & ")"
grdResults.Visible = True
grdResults.Visible = True
MousePointer = 0
End Sub
This is the clear button code:
Private Sub cmdClear_Click()
Dim ctrlObj As Control
For Each ctrlObj In Controls
If ctrlObj.Tag <> "" Then
Select Case Left$(ctrlObj.Name, 3)
Case "txt"
ctrlObj.Text = ""
End Select
End If
Next
End Sub
So how could I clear the grid, either with the clear button or to clear it when I start a new search.
Could somebody please help me with this?
regards