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

Problem with ListViewGrid

Status
Not open for further replies.

CupraSA

Technical User
Mar 14, 2009
10
0
0
ZA
Good day,

Please advise why i'm getting the following error.

380 - Invalid property value

I have the same code on a different form and it works...

Thanks

Code:
Private Sub Command2_Click()
Dim mstrSQL      As String
Dim list_item    As ListItem
    
On Error GoTo LocalError

    mstrSQL = "SELECT *" _
    & "  FROM CRLog WHERE TRSNum = '" & txtval.Text & "'" _
    & " ORDER BY RFSNum desc"

        Set mobjADORst = New ADODB.Recordset
        mobjADORst.CursorLocation = adUseClient
        mobjADORst.Open mstrSQL, mobjADOConn, adOpenDynamic, adLockOptimistic, adCmdText
        
ListViewGrid.ListItems.Clear
    With mobjADORst
        Do Until .EOF
            Set list_item = ListViewGrid.ListItems.Add(, , !Id & "", , "Search")
            list_item.SubItems(1) = !TRSNum & "" 'error occurs here...
            .MoveNext
        Loop
    End With
        
Exit Sub

LocalError:
    MsgBox Err.Number & " - " & Err.Description

End Sub
 
What is the value of "!TRSNum" when the error occurs?

You say it works fine on one form so is txtval.Text the same value on both forms, thus creating the same sql?

I suspect maybe its null so change to:

list_item.SubItems(1) = IIf(IsNull(!TRSNum), "", !TRSNum)

Tom
 
I think I'm wrong. Null would give a type mismatch. I would still check the value. I see you're using a client side cursor with a select *. I've had problems with client side cursors and the amount of columns returning.

Tom
 
When the error occurs the values are as follows:
EOF = false
list_item = "33"
list_item.SubItems(1) = <Invalid property value>
!TRSNum = "1"

The code on the other form that works is:
Code:
    strSQL = "SELECT *" _
    & "  FROM StaffTimeSheet WHERE username = '" & MainUser.Text & "'" _
    & " ORDER BY DATERECIEVED desc"
    
    mobjCmd.CommandText = strSQL
    Set mobjRst = mobjCmd.Execute
    ListViewGrid.ListItems.Clear
    
    With mobjRst
        Do Until .EOF
            Set objCurrLI = ListViewGrid.ListItems.Add(, , !Record & "", , "staffm")
            objCurrLI.SubItems(1) = !DATERECIEVED & ""
            objCurrLI.SubItems(2) = !Weekday & ""
            objCurrLI.SubItems(3) = !WeekNum & ""
The values when stepping through it are:
EOF = False
objCurrLI = "12"
objCurrLI.SubItems(1) = "2009/09/16"
!DATERECIEVED = "2009/09/16"
objCurrLI.SubItems(2) = "Wednesday"
!Weekday = "Wednesday"
objCurrLI.SubItems(3) = "38"
!WeekNum = "38
 
ok. I figured it out!!! :)

you need to added the column headers first...

Code:
Private Sub Command2_Click()
Dim mstrSQL      As String
Dim list_item    As ListItem
    
On Error GoTo LocalError
    
    With ListViewGrid
        .ColumnHeaders.Clear
        .ColumnHeaders.Add , , "Record", .Width * 0.2
        .ColumnHeaders.Add , , "TRS Number", .Width * 0.2
        .ColumnHeaders.Add , , "Status", .Width * 0.2
        .ColumnHeaders.Add , , "RFS Number", .Width * 0.2
        .ColumnHeaders.Add , , "ID", 0
    End With

    mstrSQL = "SELECT *" _
    & "  FROM CRLog WHERE TRSNum = '" & txtval.Text & "'" _
    & " ORDER BY RFSNum desc"
   
    mobjADOCmd.CommandText = mstrSQL
    Set mobjADORst = mobjADOCmd.Execute
        
ListViewGrid.ListItems.Clear
    With mobjADORst
        Do Until .EOF
            Set list_item = ListViewGrid.ListItems.Add(, , !Id & "", , "Search")
            list_item.SubItems(1) = !TRSNum & ""
            list_item.SubItems(2) = !Status & ""
            list_item.SubItems(3) = !RFSNum & ""
            list_item.SubItems(4) = CStr(!Id)
            .MoveNext
        Loop
    End With
        
Set list_item = Nothing
Exit Sub

LocalError:
    MsgBox Err.Number & " - " & Err.Description

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top