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

DataGrid and how gan I keep the values in it

Status
Not open for further replies.

stigejg

Technical User
Mar 28, 2001
55
NO
Hello,

I have som etrouble to understand the art og VB programming. I have e litle program that I mam trying to work just to learn me a litle programming.

My program has this global declarations:

Private mCN As Connection
Private mRS As New Recordset

And I want to view the tata in the database in a Datagrid an have tryed this options:

Option 1.

Private Sub cmdCollectAll1_Click()
Dim strSql As String

' Get the data for all records
strSql = "SELECT * FROM people"

mRS.Open strSql, mCN, adOpenKeyset, adLockOptimistic

Set dgTest.DataSource = mRS

End Sub

This works almost perfect, the data is viewed in my grid called dgTest. But when i want to use some other options in my program they are locked because te mRS are open. So I tryes it in option 2....

Option 2:

Private Sub cmdCollectAll2_Click()
Dim strSql As String

' Get the data for all records
strSql = "SELECT * FROM people"

mRS.Open strSql, mCN, adOpenKeyset, adLockOptimistic

Set dgTest.DataSource = mRS

MsgBox ("Stop")
mRS.Close
End Sub

This also works, but when it coms to mRS.close my grid is emptyed for data. I have to put the msgbox in to be able to se the values. But now the other optiosn in the program works again.

Option 3.

Here i trys to change the layout on my grid, but it will not work. There is no data in the grid.

Private Sub cmdCollectAll3_Click()
Dim strSql As String

' Get the data for all records
strSql = "SELECT * FROM people"

mRS.Open strSql, mCN, adOpenKeyset, adLockOptimistic


Set dgTest.DataSource = mRS
With dgTest
.Caption = ""
.Columns(0).Width = 3
.Columns(1).Width = 15
.Columns(2).Width = 15
.Columns(3).Width = 15
End With

MsgBox ("Stop")
mRS.Close
End Sub

Someone who has can explain me what to do?

best regard Stig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top