Hm. Check this whole code:
Sub ViewData()
On Error GoTo ErrHandler
Dim adoCn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim adoFld As ADODB.Field
Dim strCn As String
Dim strSQL As String
lblStatus.Caption = "Status: Viewing Data... "
txtViewData.Text = ""
'need to use microsoft access driver
'txtJetDriver.Text = {Micrsoft Access Driver (*.mdb)}
'txtDatabase.Text = Databasename.mdb
strCn = "Driver=" & txtJetDriver.Text & ";" & _
"DBQ=" & App.Path & "\" & txtDatabase.Text & ";" & _
"DefaultDir=" & App.Path & ";"
Set adoCn = New ADODB.Connection
adoCn.Open strCn '<< connection opened
'SQL statement
strSQL = "SELECT * FROM [" & txtTable.Text & "]"
Set adoRs = New ADODB.Recordset
adoRs.Open strSQL, adoCn, adOpenStatic, adLockReadOnly, adCmdText
'edit: bind recordset to the datagrid for display
Set grdViewData.DataSource = adoRs
While Not adoRs.EOF
For Each adoFld In adoRs.Fields
txtViewData.Text = txtViewData.Text & adoFld.Value & " | "
Next
txtViewData.Text = txtViewData.Text & vbCrLf
adoRs.MoveNext
Wend
GoTo ExitSub
ErrHandler:
lblStatus.Caption = "Status: Viewing Data - Error."
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
ExitSub:
If Not (adoRs Is Nothing) And (Not adoRs.State = 0) Then
lblStatus.Caption = "Status: Complete ... " & adoRs.RecordCount & " Records"
adoRs.Close
End If
Set adoRs = Nothing
adoCn.Close
Set adoCn = Nothing
End Sub
I think there's nothing wrong with that code except to the DataGrid wherein if i tried to bind the table, about 2 secs it displays the table and it scrolls down automatically O___o and then the table will disappear. I think i should use other data-binding objects.