Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
populate listbox as textbox changes question Gary Keramidas Excel Programming 1 July 15th 07 07:18 AM
Listbox value to be placed into a textbox Corey Excel Programming 3 February 7th 07 03:33 AM
Paste values from TextBox to ListBox avi Excel Programming 0 August 24th 06 05:46 PM
listbox and textbox problem jeramie[_2_] Excel Programming 2 May 22nd 06 09:15 PM
Populating TextBox Value--using ListBox jpendegraft[_15_] Excel Programming 1 May 2nd 04 03:53 AM


All times are GMT +1. The time now is 08:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"