asantos2021
New Member
- Joined
- Nov 24, 2021
- Messages
- 2
- Office Version
- 365
- 2016
- Platform
- Windows
I've been trying to put this one together, but no success so far.
It shows the userForm with empty fields and it says there's insufficient memory error, as I close the userform.
Any help will be appreciated.
VBA Code:
Option Explicit
Public Sub listBoxPopulate()
Dim data As Date
Dim BB As String
Dim CC As String
Dim DD As Date
Dim DateVal As Date
TBL = Worksheets("PartsData").Range("A1:C100")
DateVal = Selection.Value
UserForm1.ListBox1.Clear
Debug.Print DateVal
DD = 0
For BB = 1 To UBound(TBL, 1)
If Val(DateVal.Value) = Val(TBL(DD, 3)) Then
DD = DD + 1
With frmParts.ListBox1
.ColumnCount = 3
.AddItem
For CC = 1 To 3
.Column(CC - 1, DD - 1) = TBL(BB, CC)
Next CC
End With
End If
Next BB
MsgBox TBL
End Sub
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
'''find first empty row in database
''iRow = ws.Cells(Rows.Count, 1) _
'' .End(xlUp).Offset(1, 0).Row
'revised code to avoid problems with Excel tables in newer versions
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a part number
If Trim(Me.txtTask.Value) = "" Then
Me.txtTask.SetFocus
MsgBox "Please enter a task."
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 2).Value = Me.txtTime.Value
ws.Cells(iRow, 1).Value = Me.txtTask.Value
'clear the data
Me.txtDate.Value = ""
Me.txtTime.Value = ""
Me.txtTask.Value = ""
Me.txtTask.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
It shows the userForm with empty fields and it says there's insufficient memory error, as I close the userform.
Any help will be appreciated.