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

Nothing appears in MSHFlexGrid

Status
Not open for further replies.

greathope123

Programmer
Nov 1, 2011
84
GB
Hi,

This is perhaps very basic but I don't know why nothing appears in MSHFlexGrid1:

Private Sub Command1_Click()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb"
rs.Open "Select * From Table1", cn
Set MSHFlexGrid1.DataSource = rs
End Sub
 
I suggest you put in some error handling.

Try this after the rs.open

debug.print rs(0)

Anything in there?
 
Thank you.
I have just added
Debug.Print rs.RecordCount
Debug.Print rs(0)
and got
7
1
 
I've never used a MSHFlexGrid1 before and I was just trying to determine if you were bringing data back. Sorry...I can't help from here.
 
Try also:
[tt]
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset[blue]
On Error GoTo ErrHandl[/blue]
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb"
rs.Open "Select * From Table1", cn
Set MSHFlexGrid1.DataSource = rs[blue]
Exit Sub
ErrHandl:
MsgBox Err.Description[/blue]
[/tt]

and see if you have any errors in your code.

Does you code run with full compile?

Have fun.

---- Andy
 
Thank you Andy,

I have just tried your suggestion and got no error.
And can you tell me what is "full compile"?
 
I'd suspect you have the wrong cursor type for data binding.

That's some pretty rough code there. No need for a separate Connection object since you're disposing of it immediately anyway on scope exit. [tt]As New[/tt] should not be the default way you create objects. It involves additional overhead and has side effects you need to be aware of, making it a poor habit to get into.

Code:
Private Sub Command1_Click()
    Dim rs As ADODB.Recordset

    Set rs = New ADODB.Recordset
    rs.Open "Select * From Table1", _
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb", _
            adOpenStatic, _
            adLockReadOnly, _
            adCmdText
    Set MSHFlexGrid1.DataSource = rs
    rs.Close
End Sub
 
What you said is correct:
No need for a separate Connection object since you're disposing of it immediately anyway on scope exit. As New should not be the default way you create objects. It involves additional overhead and has side effects you need to be aware of, making it a poor habit to get into.
Thank you so much!

However, it still not works by your code.
 
I did use your code (I replaced the connection string and select sql with mine) and it worked just fine. I had data in my MSHFlexGrid

Full compile - in your VB 6 menu: Run, you have Start (F5) or Start with Full Compile (Cntr+F5)

Have fun.

---- Andy
 
Thank you Andrzejek.

My code is working fine in your computer......means something related with my computer system?
I am use Vista, do you think it not fully support VB6?
If my Vista do not fylly support VB6, anything I can do?
 
This is my code where I use my connection string (to Oracle) and my table:

Code:
Option Explicit

Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i As Integer

cn.Open "Driver={Microsoft ODBC for Oracle};SERVER=XYZ;"

MsgBox cn.State

rs.Open "Select * From SomeTable", cn

For i = 0 To rs.Fields.Count - 1
    MsgBox rs.Fields(i).Name
Next i

rs.Close

End Sub

First message box gives me 1 (open connection)
In next message boxes I get the names of my table's fields.

Try this on your side and see what you get.

Have fun.

---- Andy
 
Thank you.

I have tested your code:
the first message box showed 1 and the second message box showd the field names correctly.

Moreover, I used daodc + MSHFlexGrid to display data in the .mdb just fine.
 
CAn you confirm your OS , OS SP, VB6 patch level, and the version of ADO you are using?
 
Yes, they are
Windows Vista Home Premium, Service Pack 2, Upgrade Windows Vista, 32-bit Operation System
VB6.0 (SP6)
Microsoft ActiveX Data Objects 2.6 Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top