Tarkemelion
New Member
- Joined
- Jun 28, 2022
- Messages
- 21
- Office Version
- 365
- Platform
- Windows
Hi All,
It appears my code has a stack space error. I'm not entirely certain but I don't think I have an infinite call loop when the code executes. It appears the bug is subtler. Anyways, feel free to point out the issue and whether or not I'm wrong!!!
I've commented where the crash occurs to help hone in on the issue.
Best Regards and Happy Hunting
It appears my code has a stack space error. I'm not entirely certain but I don't think I have an infinite call loop when the code executes. It appears the bug is subtler. Anyways, feel free to point out the issue and whether or not I'm wrong!!!
I've commented where the crash occurs to help hone in on the issue.
VBA Code:
'UserForm Rev03
'Places UserForm in the middle of the screen
Private Sub UserForm_Activate()
Dim AppXCenter, AppYCenter As Long
AppXCenter = Application.Left + (Application.Width / 2)
AppYCenter = Application.Top + (Application.Height / 2)
With Me
.StartUpPosition = 0
.Top = AppYCenter - (Me.Height / 2)
.Left = AppXCenter - (Me.Width / 2)
End With
End Sub
Private Sub UserForm_Initialize()
'Set dimensions
With Add_New_Costing
.Width = 300
.Height = 225
End With
'Disable Previous initially
cmdPrevious.Enabled = False
'Empty Description
TextBoxDescription.Value = ""
'Empty Docket Number
TextBoxDocket.Value = ""
'Empty Date
TextBoxDate.Value = ""
'Empty Rate
TextBoxRate.Value = ""
'Empty Quantity
TextBoxQuantity.Value = ""
'Empty Unit
ComboBoxUnit.RowSource = "Table2[Unit]"
'Empty Addition
TextBoxAddition.Value = ""
'List Box 1 Populated
ComboBoxCompany.RowSource = "Table2[Company]"
'List Box 2 Populated
ComboBoxShift.List = Array("Day", "Night")
'List Box 3 Populated
ComboBoxCode.RowSource = "Table3[Code]"
End Sub
Private Sub cmdNext_Click()
'Go to Next MultiPage
MultiPage1.Value = MultiPage1.Value + 1
End Sub
Private Sub cmdPrevious_Click()
'Go to Previous MultiPage
Dim intPage As Integer
intPage = MultiPage1.Value
Do
intPage = intPage - 1
If intPage = 0 Then Exit Do
Loop While Not MultiPage1.Pages(intPage).Enabled
MultiPage1.Value = intPage
End Sub
Private Sub MultiPage1_Change()
'Enable or Disable cmdButtons if at beginning or end of Multipages
If MultiPage1.Value = 0 Then
cmdNext.Enabled = True
cmdPrevious.Enabled = False
ElseIf MultiPage1.Value = (MultiPage1.Pages.Count - 1) Then
cmdNext.Enabled = False
cmdPrevious.Enabled = True
Else
cmdNext.Enabled = True
cmdPrevious.Enabled = True
End If
End Sub
Private Sub cmdCancel_Click()
'Closes the User Form
Unload Me
End Sub
Private Sub TextBoxRate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Data Validation for TextBoxRate
'Only allows: . (fullstop); numbers; Upper Case; lower case
If (KeyAscii = 46) Or (KeyAscii > 47 And KeyAscii < 58) Then 'Or (KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123) Then
KeyAscii = KeyAscii
Else
'Otherwise, do not allow other characters
KeyAscii = 0
End If
End Sub
Private Sub TextBoxQuantity_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Data Validation for TextBoxQuantity
'Only allows: . (fullstop); numbers;
If (KeyAscii = 46) Or (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = KeyAscii
Else
'Otherwise, do not allow other characters
KeyAscii = 0
End If
End Sub
Private Sub TextBoxAddition_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Data Validation for TextBoxAddition
'Only allows: . (fullstop); numbers;
If (KeyAscii = 46) Or (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = KeyAscii
Else
'Otherwise, do not allow other characters
KeyAscii = 0
End If
End Sub
Private Sub ComboBoxCode_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Data Validation for ComboBoxCode
'Only allows: 'numbers;
If (KeyAscii > 47 And KeyAscii < 58) Then
KeyAscii = KeyAscii
Else
'Otherwise, do not allow other characters
KeyAscii = 0
End If
End Sub
Private Sub cmdAdd_Click()
'Defines the variables
Dim Company_Name As String
Dim Description As String
Dim Docket_Number As String
Dim Year As String
Dim Month As String
Dim Day As String
Dim Shift As String
Dim Code As String
Dim Rate As String
Dim Quantity As String
Dim Unit As String
Dim Addition As String
Dim ws As Worksheet
'Sets variables to UserForm values
Company_Name = ComboBoxCompany.Text
Description = TextBoxDescription.Text
Docket_Number = TextBoxDocket.Text
'Year = TextBox1.Text
'Month = TextBox2.Text
'Day = TextBox3.Text
Shift = ComboBoxShift.Text
Code = ComboBoxCode.Text
Rate = TextBoxRate.Text
Quantity = TextBoxQuantity.Text
Unit = ComboBoxUnit.Text
Addition = TextBoxAddition.Text
Set ws = ThisWorkbook.Worksheets("Cost Detail")
Set tbl = ws.ListObjects("Table2")
'Test the EnableEvents
Application.EnableEvents = False
'Add row
Dim lRow As ListRow
Set lRow = tbl.ListRows.Add ' <---- This is when the code crashes after clicking the cmdAdd button
With lRow
'.Range(1) = Year
'.Range(2) = Month
'.Range(3) = Day
.Range(4) = Shift
.Range(5) = Company_Name
.Range(6) = Description
.Range(7) = Docket_Number
.Range(8) = Code
.Range(9) = Rate
.Range(10) = Quantity
.Range(11) = Unit
.Range(12) = Addition
End With
'Test the EnableEvents
Application.EnableEvents = True
'Closes UserForm
Unload Me
End Sub
Best Regards and Happy Hunting