Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / May 2006



Tip: Looking for answers? Try searching our database.

ListView Bug

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 24 May 2006 16:05 GMT
Can some tell me why this code isn't working?

I'm using a listview control I'm retrieving field names from a database
table and making them the column headers on the listview control. I'm then
reading the data from the selected table and I want to place the data under
the correct columns.

This code has been modified from Microsoft's example to accomidate database
manipulation.

Private Sub List_Tbl_Data(cnnDB As ADODB.Connection, strTbl As String)
   On Error GoTo List_Tbl_Data_Err
   Dim I As Integer
   Dim itmX As ListItem
   Dim strFld As String
   Dim strCol As String
   Set rsData = New ADODB.Recordset
   strSQL = "SELECT " & strTbl & ".* FROM " & strTbl & ";"
   rsData.Open strSQL, cnnDB, adOpenKeyset, adLockReadOnly
   With rsData
       If .RecordCount <> 0 Then
           Do While Not .EOF
               For I = 1 To lvTblCols.ColumnHeaders.Count
                   'Get field name on listview column
                   strFld = lvTblCols.ColumnHeaders(I).Text
                   'Get the listview key
                   strCol = lvTblCols.ColumnHeaders(I).Key
                   'Write data on the proper row under the proper column
                   Set itmX = lvTblCols.ListItems.Add(I, strCol,
rsData(strFld))
               Next I
               .MoveNext
           Loop
       End If
   End With
       
List_Tbl_Data_Exit:
   On Error Resume Next
   rsData.Close
   Set rsData = Nothing
   Exit Sub
   
List_Tbl_Data_Err:
   Msg = "Error in frmPictures - List_Tbl_Data subroutine. " & vbCr & _
         "Error # " & Str(Err.Number) & " was generated by " _
         & Err.Source & vbCr & Err.Description
   MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
   Resume List_Tbl_Data_Exit
End Sub
Signature

Mark

Henning - 25 May 2006 00:13 GMT
I'm not an expert in SQL, but this might wake them up ;)
First, you're using only one Table in strSQL = "SELECT " & strTbl & ".* FROM
" & strTbl & ";"
So, you can use just SELECT * FROM tbl to get all fields in all records.

What error do you get where?

/Henning

> Can some tell me why this code isn't working?
>
[quoted text clipped - 45 lines]
>     Resume List_Tbl_Data_Exit
> End Sub
Mark - 25 May 2006 18:05 GMT
I’m not getting any errors returning database information. That is working
just fine. My problem is with the ListView Control.

Here is the code section where the error is occurring:
strSQL = "SELECT " & strTbl & ".* FROM " & strTbl & ";"
   iRow = 1
   rsData.Open strSQL, cnnDB, adOpenKeyset, adLockReadOnly
   With rsData
       If .RecordCount <> 0 Then
           Do While Not .EOF
               For I = 1 To lvTblCols.ColumnHeaders.Count
                   'Get field name on listview column
                   strFld = lvTblCols.ColumnHeaders(I).Text
                   'Get the listview key
                   strCol = CStr(lvTblCols.ColumnHeaders(I).Key)
                   'Write data on the proper row under the proper column
                   Set itmX = lvTblCols.ListItems.Add(iRow, strCol,
rsData(strFld).Value)
           ‘I get an Invalid Property error on the line below.
                   
itmX.SubItems(lvTblCols.ColumnHeaders(strCol).SubItemIndex) =
rsData(strFld).Value
               Next I
               iRow = iRow + 1
               .MoveNext
           Loop
       End If
   End With

It does not recognize the subitem value for some reason.

Thank you,

Signature

Mark

> I'm not an expert in SQL, but this might wake them up ;)
> First, you're using only one Table in strSQL = "SELECT " & strTbl & ".* FROM
[quoted text clipped - 56 lines]
> >     Resume List_Tbl_Data_Exit
> > End Sub
Henning - 26 May 2006 12:41 GMT
If you throw in the debug.print below to see what values there are, might
give a clue.

/Henning

> I'm not getting any errors returning database information. That is working
> just fine. My problem is with the ListView Control.
[quoted text clipped - 15 lines]
> rsData(strFld).Value)
>         'I get an Invalid Property error on the line below.

Debug.Print lvTblCols.ColumnHeaders(strCol).SubItemIndex
Debug.Print rsData(strFld).Value

> itmX.SubItems(lvTblCols.ColumnHeaders(strCol).SubItemIndex) =
> rsData(strFld).Value
[quoted text clipped - 69 lines]
> > >     Resume List_Tbl_Data_Exit
> > > End Sub
bitshifter - 26 May 2006 17:24 GMT
Sorry to be a Joe-come-lately but I had problems before using the
.RecordCount without doing a little dance like
.MoveLast
followed by .MoveFirst

It never hurts...

>I’m not getting any errors returning database information. That is working
>just fine. My problem is with the ListView Control.
[quoted text clipped - 89 lines]
>> >     Resume List_Tbl_Data_Exit
>> > End Sub
Henning - 26 May 2006 20:04 GMT
.RecordCount in this case, is the number of records that match the
SQL-query, here that is all records.
While I'm here, I see both ListItem and SubItem would receive the same
value.

/Henning

> Sorry to be a Joe-come-lately but I had problems before using the
> .RecordCount without doing a little dance like
[quoted text clipped - 4 lines]
>
> >Iâ?Tm not getting any errors returning database information. That is
working
> >just fine. My problem is with the ListView Control.
> >
[quoted text clipped - 88 lines]
> >> >     Resume List_Tbl_Data_Exit
> >> > End Sub
Richard Mueller - 31 May 2006 19:26 GMT
Hi,

When you retrieve RecordCount, it moves the cursor to the end of the
recordset. You need to use MoveFirst before enumerating the recordset or EOF
will be True and no records processed.

Signature

Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

> Sorry to be a Joe-come-lately but I had problems before using the
> .RecordCount without doing a little dance like
[quoted text clipped - 102 lines]
>>> >     Resume List_Tbl_Data_Exit
>>> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.