Private Sub Form_Load()
On Error GoTo ErrHandler
Dim rst As Recordset
Dim db As Database
Set db = CurrentDb
Set rst = db.OpenRecordset("Months", dbOpenTable)
With rst
If Not .EOF Then
ListBox1.Value = .Fields("CurrentMonth")
Else
ListBox1 = ListBox1.Column(0, 0)
End If
.Close
End With
ExitHere:
On Error Resume Next
Set rst = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox Err & "-" & Err.Description
Resume ExitHere
End Sub
'@-------------------------------------------------------@
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo ErrHandler
Dim rst As Recordset
Dim db As Database
Set db = CurrentDb
Set rst = db.OpenRecordset("Months", dbOpenTable)
If ListBox1.ListIndex = -1 Then GoTo ExitHere
With rst
If .EOF Then
.AddNew ' handle first unload
Else
.Edit
End If
.Fields("CurrentMonth") = ListBox1.ItemData(ListBox1.ListIndex)
.Update
.Close
End With
ExitHere:
On Error Resume Next
Set rst = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox Err & "-" & Err.Description
Resume ExitHere
End Sub