Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
Hello,
I am trying to set up a user form to add new client information as well as display the new and existing entries in a list box on the form. There are currently 22 columns / text box fields and just under 50 rows of existing entries. I'm using the following code for adding new entries and everything seems to work just fine here.
The problem is the list box doesn't display anything until I add an entry. Then it shows all the entries. However, I want it to display all the entries when the user form is activated, not just after a client is added. So I tried entering Call Show_Clients under UserForm_Activate() and later under UserForm_Initialize () separately but both end up in multiple errors and Excel crashing whenever I try to add a new entry.
Error examples:
Run-time error '-2147417848 (80010108)': Method 'Value' of object 'Range' failed... give it time, Excel crashes.
Run-time error 2147417848 Automation error... click OK, Excel crashes.
Out of stack space, Excel crashes
I can't seem to figure this one out. Is there a limit to how much data can be displayed in a list box? Any suggestions would be appreciated.
I am trying to set up a user form to add new client information as well as display the new and existing entries in a list box on the form. There are currently 22 columns / text box fields and just under 50 rows of existing entries. I'm using the following code for adding new entries and everything seems to work just fine here.
VBA Code:
Private Sub AddNewBttn_Click()
'Validations---------------------
If Me.Project.Value = "" Then
MsgBox " Enter a Project Title, please.", vbCritical, "What the heck?"
Exit Sub
End If
If Me.Customer.Value = "" Then
MsgBox " Enter a Customer Name, please.", vbCritical, "What the heck?"
Exit Sub
End If
If Me.MnContact.Value = "" Then
MsgBox " Enter a Contact Name, please.", vbCritical, "What the heck?"
Exit Sub
End If
'Check Dupe----------------------
Dim wk As Worksheet
Set wk = ThisWorkbook.Sheets("Client_Db")
If Application.WorksheetFunction.CountIf(wk.Range("A:A"), Me.Project.Value) > 0 Then
MsgBox Project.Value + " already exists!", vbCritical, "What the heck?"
Exit Sub
End If
'Add Info------------------------
Dim last_row As Integer
last_row = Application.WorksheetFunction.CountA(wk.Range("A:A"))
wk.Range("A" & last_row + 1).Value = last_row
wk.Range("B" & last_row + 1).Value = Me.Project.Value
wk.Range("C" & last_row + 1).Value = Me.Customer.Value
wk.Range("D" & last_row + 1).Value = Me.Billing_1.Value
wk.Range("E" & last_row + 1).Value = Me.Billing_2.Value
wk.Range("F" & last_row + 1).Value = Me.Billing_3.Value
wk.Range("G" & last_row + 1).Value = Me.Billing_4.Value
wk.Range("H" & last_row + 1).Value = Me.Billing_5.Value
wk.Range("I" & last_row + 1).Value = Me.Shipping_1.Value
wk.Range("J" & last_row + 1).Value = Me.Shipping_2.Value
wk.Range("K" & last_row + 1).Value = Me.Shipping_3.Value
wk.Range("L" & last_row + 1).Value = Me.Shipping_4.Value
wk.Range("M" & last_row + 1).Value = Me.Shipping_5.Value
wk.Range("N" & last_row + 1).Value = Me.PhNum.Value
wk.Range("O" & last_row + 1).Value = Me.OtherNum.Value
wk.Range("P" & last_row + 1).Value = Me.MnContact.Value
wk.Range("Q" & last_row + 1).Value = Me.OtherCont.Value
wk.Range("R" & last_row + 1).Value = Me.Email.Value
wk.Range("S" & last_row + 1).Value = Me.OtherEmail.Value
wk.Range("T" & last_row + 1).Value = Me.ShpComboBox.Value
wk.Range("U" & last_row + 1).Value = Me.ShipAcct.Value
wk.Range("V" & last_row + 1).Value = Me.Notes.Value
MsgBox "Congratulations! " + Me.Project.Value + " has been added to the database.", vbInformation, "Successful Entry"
'Clear Fields--------------------------
Me.Project.Value = ""
Me.Customer.Value = ""
Me.Billing_1.Value = ""
Me.Billing_2.Value = ""
Me.Billing_3.Value = ""
Me.Billing_4.Value = ""
Me.Billing_5.Value = ""
Me.Shipping_1.Value = ""
Me.Shipping_2.Value = ""
Me.Shipping_3.Value = ""
Me.Shipping_4.Value = ""
Me.Shipping_5.Value = ""
Me.PhNum.Value = ""
Me.OtherNum.Value = ""
Me.MnContact.Value = ""
Me.OtherCont.Value = ""
Me.Email.Value = ""
Me.OtherEmail.Value = ""
Me.ShpComboBox.Value = ""
Me.ShipAcct.Value = ""
Me.Notes.Value = ""
Call Show_Clients
End Sub
Private Sub Show_Clients()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Client_Db")
Dim last_row As Integer
last_row = Application.WorksheetFunction.CountA(ws.Range("A:A"))
With Me.ListBox1
.ColumnCount = 23
.ColumnHeads = True
.ColumnWidths = "40,150,150,120,120,120,120,120,120,120,120,120,120,72,72,120,120,120,120,80,72,200"
If last_row = 1 Then
.RowSource = "Client_Db!A2:V2"
Else
.RowSource = "Client_Db!A2:V" & last_row
End If
End With
End Sub
The problem is the list box doesn't display anything until I add an entry. Then it shows all the entries. However, I want it to display all the entries when the user form is activated, not just after a client is added. So I tried entering Call Show_Clients under UserForm_Activate() and later under UserForm_Initialize () separately but both end up in multiple errors and Excel crashing whenever I try to add a new entry.
Error examples:
Run-time error '-2147417848 (80010108)': Method 'Value' of object 'Range' failed... give it time, Excel crashes.
Run-time error 2147417848 Automation error... click OK, Excel crashes.
Out of stack space, Excel crashes
I can't seem to figure this one out. Is there a limit to how much data can be displayed in a list box? Any suggestions would be appreciated.