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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid that acts as Record Selector

Status
Not open for further replies.

Knitter

Programmer
Jul 5, 2002
9
US
I need to create a form that contains a data grid linked to a table or view of a SQL database. What this form should do is present a list of all available records, allowing a user to double-click on one record. This double-click event should bring up another form showing that record's detail.

For example, if we have a list of employees' userID, FirstName, and LastName in a list, and the user double-clicks on Nancy Jones' record in the list, the other form showing the details of Nancy's employee record should pop up.

Any ideas on how to create this interactive list object, and how to use it's properties to call a specific record's detail?

Thanks in advance.
 
I think what you want is a list. I use a list to create
a searchable, click-selectable list of items.
 
I do the same thing you are looking for..I use the data grid to display records for users. then the users can pick and choose what record they would like to view. heres how I do it..

First you need to set the Grids Datasource..

strGrid = "SELECT FIELDS FROM TABLE"

Set rsGrid = New ADODB.Recordset
rsGrid.CursorType = adOpenDynamic
rsGrid.CursorLocation = adUseClient
rsGrid.LockType = adLockPessimistic
rsGrid.Open strGrid, strCn

Set DataGrid.DataSource = rsGrid

Then on the Grids Double Click Event I have it open my detail form with the following conditions:

strRs = "SELECT FIELDS FROM TABLE WHERE FieldName = '" _
& Form.DataDrid.Columns(0) & "'"

Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
rs.LockType = adLockPessimistic
rs.Open strRs, strCn

then set your text etc..

This should get you started..



 
Thanks, dvannoy!

Just a few questions...

In your rs.open method, is strCn your data environment connection?

I can see that you're a much more advanced VB programmer than me. I have been using bound forms, rather than binding late. I think that's what your code is doing here, anyway.

If my form is frmEmployee and it's already bound to the data environment, can I call the form.show event just using the recordset filter?

I've been away from programming for a long time, and I'm trying to re-acquaint myself with the syntax of things.

Sorry to sound dumb, but it's a re-learning process.
 
heres my strCn

Global cn As ADODB.Connection
Global strCn As String

Public Function ConnectDB()

strCn = "driver={SQL Server};" & _
"server=ServerName;uid=UserID;pwd=PWD;" & _
"database=DB"

Set cn = New ADODB.Connection

With cn
.ConnectionString = strCn
.Provider = "msdasql"
.ConnectionTimeout = 60
.Open strCn
End With

End Function

I come from an access environment where I did Bind everything. once getting into VB, I did not like the bindings at all. By binding at runtime you have more control on what you need to do. but to answer your question, I think you could still call your frmEmployee form and still use the code I provided. if not you may want to not bind that recordset or form..

sorry I cant help you more with the bindings, but there are many other people here that can..

good luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top