View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Karen53 Karen53 is offline
external usenet poster
 
Posts: 333
Default 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