Search and count a string in a database

MagicAardvark

Member
Joined
Sep 10, 2010
Messages
11
Programming Experience
Beginner
I have a database program and I am wanting to search through the database to find a desired string and then count how many times the string occurs in the database.

I know this is quite simple but I just cant get my head around it. would somebody be able to provide me with the code that I could then adapt to suit my needs.

I would like it to search down a column called "DrugUse" within a database table called "TblContact" my code so far looks like
Sub Target_Count()
Dim DrugSearch As Integer
Dim ColNum As Integer
Dim RowNum As Integer
Dim RecCount As Integer
Dim drugCount As Integer
drugCount = 0
ColNum = 0
RowNum = 0
'Check Combo box if it has a value
If frmCount.comDrugsList.Text = "Amphetamines" Then
RecCount = Me.BindingContext(dsClient, "TblContact").Count
DrugSearch = frmCount.comDrugsList.SelectedValue
'move at first record
Me.BindingContext(dsClient, "TblContact").Position = 0
'loop until we find the desired Contact Person
Do While DrugSearch <> dtClient.Rows(RowNum).Item(1)
If RowNum <> RecCount Then
'move record position
Me.BindingContext(dsClient, "TblContact").Position = RowNum + 1
RowNum = RowNum + 1
Else
'exit loop if record found
Exit Do
End If
Loop
End If
End Sub
ive adapted this from a search method hense why some of it is irrelevent but any help would be appreciated because im not sure where to start.

many thanks
Kyle.
 
yes it will. What it is is a database of drug users and I want it to search through and count how many of them are using a selected drug.
 
Back
Top