• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Userform Issue

I HAVE AN ISSUE WHEN I WANT TO DISPLAY MY FORM. THIS IS MY CODE OF THE STOCK LIST, IT APPEARS HIGHLIGHTED IN THE "frm.Show". ALSO I AM ATTACH THE CODE OF formStockDetailsNew. RUN TIME ERROR 6 OVERFLOW

>>> Please, do not shouting! ~ by using capital letters <<<
>>> Modify Your writing. <<<


>>> use code - tags <<<

Code:
Option Explicit

Private Sub AddButtonn_Click()
Call AddRow
End Sub
Private Sub AddRow()
    Dim frm As New formStockDetailsNeww
    frm.Show
    Call AddDataToListBox
End Sub

Private Sub NewButton_Click()
Call NewRow
End Sub
Private Sub ButtonRemove_Click()
    Call RemoveRow
End Sub
Private Sub EditButton_Click()
    Call EditRow
End Sub
Private Sub DeleteButton_Click()
Call DeleteRow(listboxStock.ListIndex)
End Sub
Private Sub ExitButton_Click()
    Unload Me
End Sub
Private Sub UserForm_Initialize()
    Call AddDataToListBox
    Me.Width = 900
    Me.Height = 500
End Sub
Private Sub AddDataToListBox()
    'Get the Range
    Dim rg As Range
    Set rg = GetRange()
    'Link the data to the ListBox
    With listboxStock
        .RowSource = rg.Address(external:=True)
        .ColumnCount = rg.Columns.Count
        .ColumnWidths = "170;190;140;75;75;75"
        .ColumnHeads = True
        .ListIndex = 0
    End With
End Sub

Private Sub EditRow()
    ' Check if an item is selected in the ListBox
    If listboxStock.ListIndex >= 0 Then
        Dim frm As New formStockDetailsEdit
        frm.CurrentRow = listboxStock.ListIndex
        frm.Show vbModal
    Else
        MsgBox "Please select an item to edit.", vbExclamation
    End If
End Sub

Private Sub RemoveRow()
    ' Check if an item is selected in the ListBox
    If listboxStock.ListIndex >= 0 Then
        Dim frm As New RemoveQtyForm
        frm.CurrentRow = listboxStock.ListIndex
        frm.Show vbModal
    Else
        MsgBox "Please select an item to remove.", vbExclamation
    End If
End Sub
Private Sub NewRow()
    Dim frm As New AddQtyForm
    frm.CurrentRow = listboxStock.ListIndex
    frm.Show vbModal
End Sub

\\\\\\\\\\\\\\\\\\\\\\\\\\\

Private m_currentRow As Long
Private Sub buttonClose_Click()
    Unload Me
End Sub

Private Sub buttonSave_Click()

    If MsgBox("Do you wish to save this record?", vbYesNo, "Save record") = vbYes Then
  
        'Write the data to the worksheet from controls
        Call WriteDataToSheet
      
        'Empty the textboxes
        Call EmptyTextBoxes
      
        'Create a new ID
        Call CreateNewPartNumber
    End If
  
End Sub

' HELPERS
Private Function WriteDataToSheet()

    Dim NewRow As Long
    With shStock
  
        NewRow = .Cells(.Rows.Count, 1).End(xlUp).row + 1
      
        .Cells(NewRow, 1).Value = textboxPartNumber.Value
        .Cells(NewRow, 2).Value = textboxPartName.Value
        .Cells(NewRow, 3).Value = textboxManufacturer.Value
        .Cells(NewRow, 4).Value = textboxAddQuantity.Value
    End With
End Function
Public Sub EmptyTextBoxes()
    Dim c As Control
    For Each c In Me.Controls
        If TypeName(c) = "TextBox" Then
            c.Value = ""
        End If
    Next c
End Sub
Private Sub UserForm_Initialize()
    'Create a new Part Number
    Call CreateNewPartNumber
    'Initialize the controls
    Call InitializeControls
    Me.Width = 300
    Me.Height = 280
End Sub
Private Sub CreateNewPartNumber()
    Me.textboxPartNumber.Value = GetNewPartNumber()
End Sub
Public Sub InitializeControls()
    Me.comboboxArea.List = GetAreas()
    Me.comboboxArea.ListIndex = 0
End Sub
Captura de pantalla 2024-05-09 143118.pngCaptura de pantalla 2024-05-09 143411.pngCaptura de pantalla 2024-05-09 143444.png
 
Last edited by a moderator:
FOLLOW THE CODE IN DEBUG STEP BY STEP MODE IN ORDER TO FIND OUT THE CODELINE RAISING THE ERROR.​
 
In fact it returns back to this codeline calling the UserForm but this is very not the codeline raising the error​
as it is located within the UserForm code module !​
So you must find it out like I wrote in my previous post in debug step-by-step mode, hitting the F8 key …​
 
Back
Top