Howdy,
I've been teaching myself VBA and I have a question about what I do with an Object after the Sub. I'm wondering if I should always set the Object to Nothing. Below are my two examples. Thanks for any help
Public Sub MakeFormIconsListView()
Dim lstview As ListView
Dim strSQL As String
Set lstview = Form_frmicons.lview.Object
With lstview
.View = lvwReport
.ListItems.Clear
.ColumnHeaders.Clear
.AllowColumnReorder = True
.FullRowSelect = True
End With
With lstview.ColumnHeaders
.Add , , "Form", 2000
.Add , , "Location", 6000
End With
strSQL = "SELECT * FROM QRYicons;"
Set lstview = Nothing
Call FillIconListView(strSQL)
End Sub
Public Sub FillIconListView(strSQL)
Dim rst As DAO.Recordset
Dim db As Database
Dim LstItem As ListItem
Dim lstview As ListView
Set lstview = Form_frmicons.lview.Object
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
Do Until rst.EOF
Set LstItem = lstview.ListItems.Add()
LstItem.Text = Nz(rst![FrmName])
LstItem.SubItems(1) = Nz(rst![Location])
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set LstItem = Nothing
Set lstview = Nothing
DoCmd.Echo True
End Sub
I've been teaching myself VBA and I have a question about what I do with an Object after the Sub. I'm wondering if I should always set the Object to Nothing. Below are my two examples. Thanks for any help
Public Sub MakeFormIconsListView()
Dim lstview As ListView
Dim strSQL As String
Set lstview = Form_frmicons.lview.Object
With lstview
.View = lvwReport
.ListItems.Clear
.ColumnHeaders.Clear
.AllowColumnReorder = True
.FullRowSelect = True
End With
With lstview.ColumnHeaders
.Add , , "Form", 2000
.Add , , "Location", 6000
End With
strSQL = "SELECT * FROM QRYicons;"
Set lstview = Nothing
Call FillIconListView(strSQL)
End Sub
Public Sub FillIconListView(strSQL)
Dim rst As DAO.Recordset
Dim db As Database
Dim LstItem As ListItem
Dim lstview As ListView
Set lstview = Form_frmicons.lview.Object
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
Do Until rst.EOF
Set LstItem = lstview.ListItems.Add()
LstItem.Text = Nz(rst![FrmName])
LstItem.SubItems(1) = Nz(rst![Location])
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set LstItem = Nothing
Set lstview = Nothing
DoCmd.Echo True
End Sub