Click to See Complete Forum and Search --> : Search Tool


dr223
June 2nd, 2009, 05:27 AM
Hallo,

This search button works fine, however, in the tooltip it shows "Record Found" as highlighted in the code below. What I want to do is to say how many records have been found. Lets say 2 records found it says "2 Records Found". I understand a count function must be included please could anyone update the code for me to accomodate that functionality.

Thank you very much indeed. Please find the code below;

Private Sub btnPerformSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPerformSearch.Click
' Declare local variables...
Dim intPosition As Integer
' Determine the appropriate item selected and set the
' Sort property of the DataView object...
Select Case cboField.SelectedIndex
Case 0 'PRACTICE
objDataView.Sort = "PRACTICE"
Case 1 'HEALTH AUTHORITY
objDataView.Sort = "HA_NAME"
Case 2 'REGION
objDataView.Sort = "REGION"
Case 3 'TOWN
objDataView.Sort = "TOWN"
Case 4 'POSTCODE
objDataView.Sort = "POSTCODE"
Case 5 'CLINCOMP
objDataView.Sort = "CLINCOMP"
Case 6 'GPRDSTATUS
objDataView.Sort = "GPRDSTATUS"

End Select
' If the search field is not price then...
If cboField.SelectedIndex < 7 Then
' Find the practice details
intPosition = objDataView.Find(txtSearchCriteria.Text)

End If
If intPosition = -1 Then
' Display a message that the record was not found...
ToolStripStatusLabel1.Text = "Record Not Found"
Else
' Otherwise display a message that the record was
' found and reposition the CurrencyManager to that
' record...
ToolStripStatusLabel1.Text = "Record Found"
objCurrencyManager.Position = intPosition
End If
' Show the current record position...
ShowPosition()

End Sub

HanneSThEGreaT
June 2nd, 2009, 09:32 AM
Would something like this :
ToolStripStatusLabel1.Text = objDataView.Count & " Record(s) Found"

Work ¿

dr223
July 14th, 2009, 04:41 AM
Hallo,

I have th efollowing search code which works fine. However, I have an additional task to do, which is create a count funtion for the Record found or Record not found. Presently what it does is it searchs and if a record is found it displays at the tooltip "Record Found" if not it says "Record Not found". However, sometimes you have 2 or more records. Therefore, the tooltip should say the exact amount of records found.. For example, 3 Records Found or even 5 Records Found.

Also if only one record is found it says "Record Found" but if more it should display " 2 Records Found".

Please could anyone help me with the count syntax to be added to the code.. Thanks


Private Sub btnPerformSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPerformSearch.Click
' Declare local variables...
Dim intPosition As Integer
' Determine the appropriate item selected and set the
' Sort property of the DataView object...
Select Case cboField.SelectedIndex
Case 0 'PRACTICE
objDataView.Sort = "PRACTICE"
Case 1 'HEALTH AUTHORITY
objDataView.Sort = "HA_NAME"
Case 2 'REGION
objDataView.Sort = "REGION"
Case 3 'TOWN
objDataView.Sort = "TOWN"
Case 4 'POSTCODE
objDataView.Sort = "POSTCODE"
Case 5 'CLINCOMP
objDataView.Sort = "CLINCOMP"
Case 6 'GPRDSTATUS
objDataView.Sort = "GPRDSTATUS"

End Select
' If the search field is not price then...
If cboField.SelectedIndex < 7 Then
' Find the practice details
intPosition = objDataView.Find(txtSearchCriteria.Text)

End If
If intPosition = -1 Then
' Display a message that the record was not found...

ToolStripStatusLabel1.ForeColor = Color.Red
ToolStripStatusLabel1.Font = New Font(Font, FontStyle.Bold)
ToolStripStatusLabel1.Text = "Record Not Found"
Else
' Otherwise display a message that the record was
' found and reposition the CurrencyManager to that
' record...
ToolStripStatusLabel1.ForeColor = Color.Red
ToolStripStatusLabel1.Font = New Font(Font, FontStyle.Bold)
ToolStripStatusLabel1.Text = "Record Found"
objCurrencyManager.Position = intPosition
End If
' Show the current record position...
ShowPosition()

Me.QryContactsperpracTableAdapter1.FillBy(Me.QryContacts1.QryContactsperprac, TxtPracName.Text, TxtPostcode.Text, TxtSite.Text, TxtAddress1.Text)

End Sub

HanneSThEGreaT
July 14th, 2009, 06:34 AM
What's was wrong with this answer ¿ :

http://www.codeguru.com/forum/showthread.php?t=478239

Couldn't you manage to get it to work ¿ :)

dr223
July 14th, 2009, 07:38 AM
This code did not work...

It displayed the number of all records on the tooltip

as

9134 Record(s) Found

This was shown even if ONLY 2 records were present...

any help!!!

Thanks for the suggestion

dr223
July 14th, 2009, 07:46 AM
This code did not work...

It displayed the number of all records on the tooltip

as

9134 Record(s) Found

This was shown even if ONLY 2 records were present...

any help!!!

Thanks for the suggestion

HanneSThEGreaT
July 14th, 2009, 08:10 AM
Hello again. I need glasses! :lol: :blash: I don't know how I could've missed this one :)

You've already set it up properly actually. You already had a variable ( intPosition ) pointing to the Find results...

Change the appropriate section to look like :
Else
' Otherwise display a message that the record was
' found and reposition the CurrencyManager to that
' record...
ToolStripStatusLabel1.ForeColor = Color.Red
ToolStripStatusLabel1.Font = New Font(Font, FontStyle.Bold)
ToolStripStatusLabel1.Text = intPosition " Record(s) Found"
objCurrencyManager.Position = intPosition

I apologise for my blindness, it happens sometimes, but I sincerely hope it helps now. :)

dr223
July 14th, 2009, 09:04 AM
The problem is it doesn't show the number of records obtained..

I want it to tell the user if the number of records are 2, 10, 1000 etc

Therefore it should look like, for example - 2 Record(s) Found or 1000 Record(s) Found

any ideas