Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Data Control give sql select results and display in FormTextboxes?

Status
Not open for further replies.

StlMacMan

Technical User
Jan 21, 2005
41
US
I have a VB6 Form1 w/ several Textboxes into which the user enters data which is stored in an Access db. I have been able to use a sql statement (not an ADO Data Control) to search for some individual recordset in the db by a certain field value and to display the result on another Form2 which is set up like the entry form so that the db fields populate the appropriate Textboxes.

Here's the problem--I also need to be able to search for all the records in the db that contain a certain field value and would like them to populate Form2 in the appropriate Textboxes and allow the user to step through all and only those records that contain that value. Can the ADO Data Control do that using the RecordSource String rather than the Table option? Is there some non-ADO Data Control method to hold the query data and display it as the user selects it in some way? Am I thinking about this the wrong way? If someone can point me in a direction that shows how can this be done, I'd appreciate it. Thanks.--Ed
 
You have already done most of the work if you can return a recordset from SQL without a datacontrol. All you need to do is to step through your recordset (assuming it's not a Forward only cursor) using the MoveNext, MovePrevious, MoveFirst and MoveLast methods and repopulate your textboxes.

If Not rs.EOF Then
rs.MoveNext
Else
rs.MoveFirst
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
End If

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
John--Thanks for the response. Two questions. What triggers the MoveNext? Also, after inserting

rs.MoveNext
Else
rs.MoveFirst

between my already existing EOF statement and my Text = Fields statements, I get no display in the Form boxes. What do you think? --Ed
 
You'll need to put some controls in (like Next and Previous command buttons). You'll also need to check that there are records in the recordset. The code I posted was just to give a flavour of moving through the recordset and was not intended as production code.

Without more detail of your problem and target result it's hard to be more specific. Did you read faq222-2244 for guidance on forum use?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Thanks again, John, for the pointers. I'll work on the Move controls and see what I can do. I have read the FAQ and hoped my description was detailed enough to get at what I'm after. Sorry if it wasn't.--Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top