Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
New Member
Posts: 4
Registered: ‎08-15-2009

Unbound Datagrid - Records won't show until scrollup

Hi,

 

I am populating datagrid with data from external database table. Grid will show empty even after grid refresh.

But, records show only after scroll up.  I am not sure what is missing?

 

I set KeyField property and populating grid via code using Recordset. I attached document explaining issue.

 

I really appreciate for any clue.

 

Sub PopulateCustomers(strSearch)
Dim strDBServer,strDB,strLogin,strPassword, strConn, objRS, cn, strSQL

strDBServer = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSDBServer'")
strDB = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSDB'")
strLogin = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSLogin'")
strPassword = "" & GetField("Element_Value", "C_Manage_RFMS", "Element = 'RFMSPWD'")
strConn = "Provider = SQLOLEDB; Data Source = " & strDBServer & "; Initial Catalog = " & strDB & "; User Id = " & strLogin & "; Password = " & strPassword & ";"

Set cn = CreateObject("ADODB.Connection")

cn.Open strConn

If Err.Number <> 0 Then
Msgbox Err.Source & ": " & Err.Description, 0, "Error in connecting to RFMS Database!"
Err.Clear
Exit Sub
End If

if(strSearch<>"") then
strSQL = "select Top 100 'F' as Tag,SeqNum,Cust_Name from Customer WHERE Cust_name Like '" & strSearch & "%'"
else
strSQL = "select Top 100 'F' as Tag,SeqNum,Cust_Name from Customer"
END IF

' if(strSearch<>"") then
'' strSQL = "select Top 100 SeqNum,Cust_Name from Customer WHERE Cust_name Like '" & strSearch & "%'"
'else
'' strSQL = "select Top 100 SeqNum,Cust_Name from Customer"
' END IF

Set objRS = CreateObject("ADODB.Recordset")

With objRS
Set .ActiveConnection = cn
.Open strSQL
End With


CreateGridRecordSet dgCustomers

while Not objRS.EOF

With dgCustomers.Recordset
.AddNew
.Fields("TAG").Value = objRS.Fields("TAG").Value
.Fields("SEQNUM").Value = objRS.Fields("SEQNUM").Value
.Fields("CUST_NAME").Value = objRS.Fields("CUST_NAME").Value
.Update
End With

objRS.MoveNext
wend

dgCustomers.Refresh


objRS.Close
Set objRS = Nothing
End Sub

 

 

 

 

 

Highlighted
Silver Super Contributor
Posts: 801
Registered: ‎03-24-2009

Re: Unbound Datagrid - Records won't show until scrollup

Best way is to do the following: Within the Sub PopulateCustomers(strSearch) do this: dgCustomers.RecordSet = objRS.RecordSet You can then discard everything else. It will automatically refresh. This assumes that dgCustomers already has a layout (e.g. a set of columns ready to receive whatever you are pulling back in objRS into dgCustomers.recordset. If not, you'll either have to fake it (by adding fake cols of the same type) or create the relevant recordset manually for dgCustomers.