Listview gives me a type mismatch???? (1 Viewer)

greenguy

Registered User.
Local time
Today, 01:35
Joined
Oct 30, 2007
Messages
36
Howdy,

I've made several listviews (Microsoft Listview Control, Version 6.0) and now I'm getting a type mismatch error. When the form opens I am calling a sub in a module to create and fill the list view. I highlighted where I am getting the error. Am I getting this because I am trying to create it during the Form Open event? Any advice would be great!


Sub Fill_Capacity_ListView()
Dim strSQL As String
Dim LView As ListView
Dim lstitem As ListItem
Dim db As Database
Dim rst As DAO.Recordset

Set db = CurrentDb
strsq = "SELECT * FROM tblcapacity;"
Set LView = Form_frmcapacitysettings.lstview.Object
With LView
.ListItems.Clear
.View = lvwReport
End With

With LView.ColumnHeaders
.Add , , "Incr", 0
.Add , , "Area", 1200
.Add , , "Rate", 1200
.Add , , "Hours/Day", 1200
.Add , , "Days/Week", 1200
End With
 

boblarson

Smeghead
Local time
Yesterday, 23:35
Joined
Jan 12, 2001
Messages
32,059
Change this:

Set LView = Form_frmcapacitysettings.lstview.Object

to this

Set LView = Forms!frmcapacitysettings.lstview
 

greenguy

Registered User.
Local time
Today, 01:35
Joined
Oct 30, 2007
Messages
36
Hi Bob,

Still getting a type mismatch.

Changed it to Set LView = Forms!frmcapacitysettings.lstview

Hmmm this happens every once in a while. Hmmmm any other thoughts?

Thanks for the quick response!
 

boblarson

Smeghead
Local time
Yesterday, 23:35
Joined
Jan 12, 2001
Messages
32,059
The only thing I can see that might be it is if the form or listview name is misspelled, or that it doesn't like the object type. Are there more than one LISTVIEW listed when you type Dim LView As
 

greenguy

Registered User.
Local time
Today, 01:35
Joined
Oct 30, 2007
Messages
36
Hey Bob,

I deleted the form, recreted it from scratch and placed this code into my Module. It works. When I didn't add the ".Object" I got a Type Mismatch error. Again, I'm not sure what really made this work but it does so I'll move forward.

I am somewhat of a rookie at this so I'm not sure what the difference is between Forms!frmcapacitysettings and Form_frmcapacitysettings

Sub Fill_Test()
Dim Lview As ListView
Dim lstitem As ListItem
Set Lview = Forms!frmcapacitysettings.lstview.Object
With Lview
.ColumnHeaders.Clear
.View = lvwReport
End With
With Lview.ColumnHeaders
.Add , , "Test", 1500, lvwColumnLeft
.Add , , "Test1", 1500, lvwColumnLeft
.Add , , "Test2", 1500, lvwColumnLeft
End With
End Sub
 

mrgreen

Registered User.
Local time
Yesterday, 23:35
Joined
Jan 11, 2008
Messages
60
LOL I did have multiple references. Ugh. Well thanks dcb and Bob for helping me with this - it's been driving me crazy!
 

dcb

Normally Lost
Local time
Today, 08:35
Joined
Sep 15, 2009
Messages
529
Glad to help - even if i can't type or spell tonight
 

Users who are viewing this thread

Top Bottom