Search code in a database

Reply

Join Date: Jul 2005
Posts: 19
Reputation: user777 is an unknown quantity at this point 
Solved Threads: 0
user777 user777 is offline Offline
Newbie Poster

Search code in a database

 
0
  #1
Aug 3rd, 2005
Hi Everybody,

Could somebody let me know the search code in a database (mdb database : with 1 table only) to write for a search command. I am using ADODC1 connection.

Please also let me know for the above table if i want to add a new contact to the table when i write contact name in a text box it should be automatically changed to upper case even i write in a lower case.

Have a nice day..

Note: I used this code for the search command but it did not work.

Private Sub Command8_Click()
Dim Searchvar As String
Dim sBookMark As String
Searchvar = InputBox("Enter the Name to find")
Searchvar = Trim$(Searchvar) 'remove surplus spaces
If Searchvar <> " " Then 'cancel if nothing entered
With Adodc1.Recordset
sBookMark = .Bookmark
.FindFirst "SName like '" + Searchvar + "*'"
If .NoMatch Then 'record not found
MsgBox "Hey! There is no such record in this Database
.Bookmark = sBookMark
End If
End With
End If
End Sub

When i tried this one there was an error: "Method or Data Member not found" and it highlights this string in the code : ".FindFirst"

user777
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 514
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: Search code in a database

 
0
  #2
Aug 3rd, 2005
Why not just use DAO?

Much Cleaner in my opinion


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim rst As DAO.Recordset
  2. Dim db As Database
  3. Set db = CurrentDb()
  4. Set rst = db.OpenRecordset("select [field1],[field2] from table where [fieldID] = '" & Me.Something.Value & "'")
  5. rst.Close
  6. Set db = Nothing
  7. End If
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 104
Reputation: Alvein is an unknown quantity at this point 
Solved Threads: 4
Alvein's Avatar
Alvein Alvein is offline Offline
Junior Poster

Re: Search code in a database

 
0
  #3
Aug 3rd, 2005
Originally Posted by user777
With Adodc1.Recordset
.FindFirst "SName like '" + Searchvar + "*'"
If .NoMatch Then 'record not found
Obviously "FindFirst" is not supported (neither "NoMatch"). But let's simulate it:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. .MoveFirst
  2. .Find "SName like '" & Searchvar & "*'"
  3. If (.EOF) Then 'record not found
Damn it, I still dream of her....:(
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 29
Reputation: vhinehds is an unknown quantity at this point 
Solved Threads: 0
vhinehds's Avatar
vhinehds vhinehds is offline Offline
Light Poster

Re: Search code in a database

 
0
  #4
Aug 4th, 2005
hi to all...

maybe this one will help...here it is:

********** this is an unbound control *************
***** create first and active connection ***********


Private Sub text1_KeyPress(KeyAscii As Integer)
dim RS as New ADODB.Recordset

If KeyAscii = 13 Then

set RS = new adodb.recordset
RS.open "select * from [tablename]",activeconnection,adOpenDynamic,
adLockOptimistic

with RS

.find "[fieldname] = '" & text1.text & "'", , adSearchForward

if not .eof then

msgbox "Record found."

else

msgbox "No Record."

endif

end with



End If

End Sub
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 2
Reputation: jumel_19 is an unknown quantity at this point 
Solved Threads: 0
jumel_19 jumel_19 is offline Offline
Newbie Poster

Re: Search code in a database

 
0
  #5
Sep 27th, 2007
hey guys you have answered my question thanks.....
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 1
Reputation: babykhulet`me is an unknown quantity at this point 
Solved Threads: 0
babykhulet`me babykhulet`me is offline Offline
Newbie Poster

Re: Search code in a database

 
0
  #6
May 12th, 2009
Originally Posted by vhinehds View Post
hi to all...

maybe this one will help...here it is:

********** this is an unbound control *************
***** create first and active connection ***********


Private Sub text1_KeyPress(KeyAscii As Integer)
dim RS as New ADODB.Recordset

If KeyAscii = 13 Then

set RS = new adodb.recordset
RS.open "select * from [tablename]",activeconnection,adOpenDynamic,
adLockOptimistic

with RS

.find "[fieldname] = '" & text1.text & "'", , adSearchForward

if not .eof then

msgbox "Record found."

else

msgbox "No Record."

endif

end with



End If

End Sub

what if i want the result to be displayed on the textbox/listbox, then if i choose the name, the other info about the name that is chosen will change also to their corresponding info.. what will i do in this given code?.. =) hope you can help me guys!.. tnx a lot in advance..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC