|
-
Feb 25th, 2007, 08:37 PM
#1
Thread Starter
Junior Member
[RESOLVED] Search problem
I have a database in access connected though ADO.
I want to retrieve data from the table that contains many fields using a command button once inputed a unique field (id) and get rest of fields onto remaining textboxes.
Thanks in advance
-
Feb 26th, 2007, 07:22 AM
#2
Re: Search problem
VB Code:
Dim sSQL As String
sSQL = "SELECT field1, field2, field3 etc FROM tablename "
sSQL = sSQL & "WHERE idfieldname = '" & txtId.Text & "' "
Set rs = New ADODB.Recordset
rs.Open sSQL, AdoConnectionObjName
Text1.Text = rs.Fields.Item("field1").Value
Text2.Text = rs.Fields.Item("field2").Value
Text3.Text = rs.Fields.Item("field3").Value
etc
rs.Close
Set rs = Nothing
Where rs is the name of your recordset object and AdoConnectionObjName is the name of your connection object.
-
Feb 26th, 2007, 12:56 PM
#3
Thread Starter
Junior Member
Re: Search problem
Thank for the reply hack,
What if the id it's not unique because have different dates?. If i have a button to scroll through the different dated id's and display rest of info on the textboxes.
Thanks in advance
-
Feb 26th, 2007, 01:16 PM
#4
Re: Search problem
Either select based on id and date to get a unique record, or select on based on id and get all records for that id.
"WHERE idfieldname = '" & txtId.Text & "' And DateFieldName = #" & txtDate.Text & "#"
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Feb 27th, 2007, 07:28 PM
#5
Thread Starter
Junior Member
Re: Search problem
Thank for the reply,
Now i´m having a problem, any value i input in the id txtbox returns the first row of the database.
Al42,
What i want it´s to retrive several records with the same id but different dates only.
Thanks in advance.
-
Feb 27th, 2007, 07:38 PM
#6
Addicted Member
Re: Search problem
cant you use what hack gave you to select the data then just use a for loop to display all records matching it?
Im not sure on the code
rs.Open sSQL, AdoConnectionObjName
for i = 1 to rs.recordcount
'Text1.Text = rs.Fields.Item("field1").Value
'Text2.Text = rs.Fields.Item("field2").Value
'Text3.Text = rs.Fields.Item("field3").Value
'etc
rs.movenext
next
rs.Close
Last edited by Ishamael; Feb 27th, 2007 at 07:39 PM.
Reason: bah
-
Feb 27th, 2007, 08:53 PM
#7
Re: Search problem
if your returning several records then you might want to consider grid-like controls such as flexgrid or listview. Otherwise, using textboxes, you will have to provide control for navigating through the records. Often this is accomplished with data bound ado control but most would advise against using databound controls.
-
Mar 17th, 2007, 06:33 PM
#8
Thread Starter
Junior Member
Re: Search problem
Thanks all for your help.....Resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|