ListBox & TextBox Save

G

Guest

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
 
G

Guest

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.
 
G

Guest

Hi Joel,

Thank you for the info. I am not adding a new row in this procedure though.
I am changing existing data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Save Textbox into Named Range 2
Sheet protection 1
Help with find/replace 2
Copy filtered data to sheet 2 1
Help with array 3
Blank item in listbox, how to remove 3
Type Mismatch 4
Changed variable value 6

Top