944,147 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Aug 3rd, 2005
-1

Search code in a database

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
user777 is offline Offline
19 posts
since Jul 2005
Aug 3rd, 2005
-1

Re: Search code in a database

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
Reputation Points: 12
Solved Threads: 19
Posting Pro
techniner is offline Offline
521 posts
since May 2005
Aug 3rd, 2005
0

Re: Search code in a database

Quote 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
Reputation Points: 12
Solved Threads: 4
Junior Poster
Alvein is offline Offline
104 posts
since Jul 2005
Aug 4th, 2005
0

Re: Search code in a database

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
Reputation Points: 11
Solved Threads: 0
Light Poster
vhinehds is offline Offline
29 posts
since May 2005
Sep 27th, 2007
0

Re: Search code in a database

hey guys you have answered my question thanks.....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jumel_19 is offline Offline
2 posts
since Sep 2007
May 12th, 2009
0

Re: Search code in a database

Click to Expand / Collapse  Quote originally posted by vhinehds ...
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..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
babykhulet`me is offline Offline
1 posts
since May 2009
Jul 1st, 2010
0
Re: Search code in a database
hi need more sample like how to add listbox etc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
KEMSHA is offline Offline
1 posts
since Jul 2010
Aug 16th, 2010
0

DAO searching Code please...

Is there anyone here that can help me w/ my problem?

I'm trying to create Searching Code (using DAO).
how can I code this...
Database is MS Access 2003.
I want to search in my Database, in 1 table, 1 field and filter it.
for Example: if i just want to search all the records under year 2010, or Aug,2008
or from Aug-Nov 2008. Obviously, its just under DATE field. Is
that possible?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ComputerHacker is offline Offline
4 posts
since Aug 2010
Aug 16th, 2010
1
Re: Search code in a database
ComputerHacker, firstly please read our posting rules. You need to open your own thread with your question/problem. This is a VERY old post that has been reraised from the dead, and normally we would not even reply on this. You are however a new poster, so I'll answer the basics, and if you open your own thread we will help where we can.

Your question, yes it is possible, depending on your usage of getting the data, is it a datacontrol, ADO etc.?

Your code will look something like -

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. rsDate.Open "SELECT * FROM MyTable WHERE MyDate >= DateValue('" & txtDate.Text & "')", cnMyConnection, adOpenStatic, adLockOptimistic

Let us know if you encountered more problems in your OWN post please.
Reputation Points: 329
Solved Threads: 347
Senior Poster
AndreRet is offline Offline
3,700 posts
since Jan 2008
Aug 18th, 2010
0
Re: Search code in a database
yes tnx for your reply...I admit I'm just a Newbee on this Forum...Can you just teach me how to Open a New Thread?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ComputerHacker is offline Offline
4 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VBA Function Resistor
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Rfid Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC