![]() |
ListBox & TextBox Save
Hi,
I've been going round and round with this and can't figure out why only my first textbox saves the new data. I have a list box for the user to select from. I save the index number in choice. The list is based on a named range 'Tenants'. I have a text box for each item. The listbox displays the data perfectly as do the textboxes. The associated text boxes do not save the data to the worksheet, except the first box, TenantName. That one works. What am I missing? Thanks. Private Sub lboChoseTenant_Change() Dim Choice As Long 'increase one as index starts at 0 Choice = lboChoseTenant.ListIndex + 1 Me.txtTenantName = Range("Tenants").Item(Choice, 4) Me.txtPrimaryUnitNo = Range("Tenants").Item(Choice, 2) Me.txtAddUnitNos = Range("Tenants").Item(Choice, 3) Me.txtDaysOccupied = Range("Tenants").Item(Choice, 6) Me.txtRentalTax = Range("Tenants").Item(Choice, 7) End Sub Private Sub cmdSave_Click() Dim Choice As Long 'increase one as index starts at 0 Choice = lboChoseTenant.ListIndex + 1 'save any changes Range("Tenants").Item(Choice, 4).Value = Me.txtTenantName Range("Tenants").Item(Choice, 2).Value = Me.txtPrimaryUnitNo Range("Tenants").Item(Choice, 3).Value = Me.txtAddUnitNos Range("Tenants").Item(Choice, 6).Value = Me.txtDaysOccupied Range("Tenants").Item(Choice, 7).Value = Me.txtRentalTax End Sub I also tried setting Choice value before each textbox... 'save any changes Choice = lboChoseTenant.ListIndex + 1 Range("Tenants").Item(Choice, 4).Value = Me.txtTenantName Choice = lboChoseTenant.ListIndex + 1 Range("Tenants").Item(Choice, 2).Value = Me.txtPrimaryUnitNo etc... I also tried using the A1 address Range("C" & Choice).Value = Me.txtPrimaryUnitNo |
ListBox & TextBox Save
IF YOU ARE ADDING A NEW ROW TO THE LISTBOX THEN YOU HAVE TO USE THE ADDITEM
METHOD. GET THE "LISTCOUNT". THE 1ST ENTRY IS 0, SO THE INDEX THAT YOU WRITE TO AND THE COUNT DIFFERER BY 1. "Karen53" wrote: Hi, I've been going round and round with this and can't figure out why only my first textbox saves the new data. I have a list box for the user to select from. I save the index number in choice. The list is based on a named range 'Tenants'. I have a text box for each item. The listbox displays the data perfectly as do the textboxes. The associated text boxes do not save the data to the worksheet, except the first box, TenantName. That one works. What am I missing? Thanks. Private Sub lboChoseTenant_Change() Dim Choice As Long 'increase one as index starts at 0 Choice = lboChoseTenant.ListIndex + 1 Me.txtTenantName = Range("Tenants").Item(Choice, 4) Me.txtPrimaryUnitNo = Range("Tenants").Item(Choice, 2) Me.txtAddUnitNos = Range("Tenants").Item(Choice, 3) Me.txtDaysOccupied = Range("Tenants").Item(Choice, 6) Me.txtRentalTax = Range("Tenants").Item(Choice, 7) End Sub Private Sub cmdSave_Click() Dim Choice As Long 'increase one as index starts at 0 Choice = lboChoseTenant.ListIndex + 1 'save any changes Range("Tenants").Item(Choice, 4).Value = Me.txtTenantName Range("Tenants").Item(Choice, 2).Value = Me.txtPrimaryUnitNo Range("Tenants").Item(Choice, 3).Value = Me.txtAddUnitNos Range("Tenants").Item(Choice, 6).Value = Me.txtDaysOccupied Range("Tenants").Item(Choice, 7).Value = Me.txtRentalTax End Sub I also tried setting Choice value before each textbox... 'save any changes Choice = lboChoseTenant.ListIndex + 1 Range("Tenants").Item(Choice, 4).Value = Me.txtTenantName Choice = lboChoseTenant.ListIndex + 1 Range("Tenants").Item(Choice, 2).Value = Me.txtPrimaryUnitNo etc... I also tried using the A1 address Range("C" & Choice).Value = Me.txtPrimaryUnitNo |
ListBox & TextBox Save
Hi Joel,
Thank you for the info. I am not adding a new row in this procedure though. I am changing existing data. "Joel" wrote: IF YOU ARE ADDING A NEW ROW TO THE LISTBOX THEN YOU HAVE TO USE THE ADDITEM METHOD. GET THE "LISTCOUNT". THE 1ST ENTRY IS 0, SO THE INDEX THAT YOU WRITE TO AND THE COUNT DIFFERER BY 1. "Karen53" wrote: Hi, I've been going round and round with this and can't figure out why only my first textbox saves the new data. I have a list box for the user to select from. I save the index number in choice. The list is based on a named range 'Tenants'. I have a text box for each item. The listbox displays the data perfectly as do the textboxes. The associated text boxes do not save the data to the worksheet, except the first box, TenantName. That one works. What am I missing? Thanks. Private Sub lboChoseTenant_Change() Dim Choice As Long 'increase one as index starts at 0 Choice = lboChoseTenant.ListIndex + 1 Me.txtTenantName = Range("Tenants").Item(Choice, 4) Me.txtPrimaryUnitNo = Range("Tenants").Item(Choice, 2) Me.txtAddUnitNos = Range("Tenants").Item(Choice, 3) Me.txtDaysOccupied = Range("Tenants").Item(Choice, 6) Me.txtRentalTax = Range("Tenants").Item(Choice, 7) End Sub Private Sub cmdSave_Click() Dim Choice As Long 'increase one as index starts at 0 Choice = lboChoseTenant.ListIndex + 1 'save any changes Range("Tenants").Item(Choice, 4).Value = Me.txtTenantName Range("Tenants").Item(Choice, 2).Value = Me.txtPrimaryUnitNo Range("Tenants").Item(Choice, 3).Value = Me.txtAddUnitNos Range("Tenants").Item(Choice, 6).Value = Me.txtDaysOccupied Range("Tenants").Item(Choice, 7).Value = Me.txtRentalTax End Sub I also tried setting Choice value before each textbox... 'save any changes Choice = lboChoseTenant.ListIndex + 1 Range("Tenants").Item(Choice, 4).Value = Me.txtTenantName Choice = lboChoseTenant.ListIndex + 1 Range("Tenants").Item(Choice, 2).Value = Me.txtPrimaryUnitNo etc... I also tried using the A1 address Range("C" & Choice).Value = Me.txtPrimaryUnitNo |
All times are GMT +1. The time now is 07:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com