Use the same select statement type -
SELECT * FROM student WHERE StudentName LIKE " & "'" & Nav & "%'"
This will return all the names that has Nav in its text.
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
You can use this code to check wether a query result returns a macthing record or not
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
'NOTE: you can use AndreRet's given example above this post...
rs.Open "YOUR SELECT STATEMENT HERE", cn, adOpenKeyset, adLockOptimistc, adCmdText
If rs.BOF and rs.EOF = True then 'if there are no results from the query, then do this (this means that there are no records)
Else 'when the query have return a number of matching records...do this
End if
PoisonedHeart
Junior Poster in Training
57 posts since Jul 2009
Reputation Points: 14
Solved Threads: 14
rs.Open "YOUR SELECT STATEMENT HERE", cn, adOpenKeyset, adLockOptimistc, adCmdText
As in -
rs.Open "SELECT * FROM student WHERE StudentName LIKE " & "'" & Nav & "%'", cn, adOpenStatic, adLockOptimistic
.:)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
'Declare the ADODB objects
Dim cnMyCon As ADODB.Connection
Dim rsMyRec As ADODB.RecordSet
Set a reference to the ADODB that will be used in this context
Set cnMyCon = New ADODB.Connection
Set rsMyRec = New ADODB.RecordSet
'Do your access database connection here.
cnMyCon.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= WhereYourPathOfDatabaseIS\YourDatabaseName.MDB;Persist Security Info=False"
If txtstudentid.Text = nul Then
MsgBox "Field Must Be Entered", vbOKOnly + vbExclamation, "EXCELLENT ACADMY"
txtstudentid.SetFocus
Exit Sub
Else
rsMyRec.Open "SELECT * FROM YourTableName WHERE TheStudentIdNumber = " & "'" & txtstudentid.Text & "'"
If rsMyRec.BOF = True Or rsMyRec.EOF = True Then
'Add the new record here because it does not exist
Else
msgbox "Record already exist.",vbexclamation
cnMyCon.Close
rsMyRec.Close
exit sub
End If
End IF
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
It was only a pleasure.:)
I see that you had your txtStudentId set to your datacontrol. Nicely done to compare from there.
Please mark this thread as solved for us, thanks.
Happy coding.:)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350