Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Using a form to modify a list

i have a range of data named members in a worksheet, sheet1. when the
userform loads, a listbox on the form is filled with data from "members". on
the Click event for the list box, a series of textboxes are filled with data
from the range "members" by this code:


Private Sub LBMemberDatasheetForm_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows _
(Me.ListBoxMemberDatasheetForm.ListIndex + 1)

If Me.ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
.TBMemDataAddress1.Text = RowRange.Columns(1).Value
.TBMemDataAddress2.Text = RowRange.Columns(2).Value
.TBMemDataApt.Text = RowRange.Columns(3).Value
.TBMemDataCity.Text = RowRange.Columns(4).Value
.TBMemDataState.Text = RowRange.Columns(5).Value
.TBMemDataZip.Text = RowRange.Columns(6).Value
.TBMemDataPhone.Text = RowRange.Columns(7).Value
.TBMemDataMobile.Text = RowRange.Columns(8).Value
.TBMemDataEmail.Text = RowRange.Columns(9).Value
End With
End If
End Sub

This code works fine, and fast to fill the 9 text boxes with data. i have
another macro that runs when the user clicks ok. this takes the information
from the textboxes, and back to the record indicated by RowRange:


Private Sub MemDataOKButton_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows _(ListBoxMemberDatasheetForm.ListIndex
+ 1)

If ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
RowRange.Columns(1).Value = .TBMemDataAddress1.Text
RowRange.Columns(2).Value = .TBMemDataAddress2.Text
RowRange.Columns(3).Value = .TBMemDataApt.Text
RowRange.Columns(4).Value = .TBMemDataCity.Text
RowRange.Columns(5).Value = .TBMemDataState.Text
RowRange.Columns(6).Value = .TBMemDataZip.Text
RowRange.Columns(7).Value = .TBMemDataPhone.Text
RowRange.Columns(8).Value = .TBMemDataMobile.Text
RowRange.Columns(9).Value = .TBMemDataEmail.Text
End With
End If

This macro only works on the first text box. meaning that it only updates
the 1st column in RowRange. if i modify Address2, then click ok, the textbox
goes back to blank, and does not update the record. please help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using a form to modify a list

Instead of using rowsource to populate your listbox, use code.

Private sub Userform_Initialize()
Me.ListBoxMemberDatasheetForm.List = Range("Members").Value

' or
'Me.ListBoxMemberDatasheetForm.List = Range("Members").Columns(1).Value
' depending on what is in the listbox
End Sub

--
Regards,
Tom Ogilvy

"Spencer Hutton" wrote in message
...
i have a range of data named members in a worksheet, sheet1. when the
userform loads, a listbox on the form is filled with data from "members".

on
the Click event for the list box, a series of textboxes are filled with

data
from the range "members" by this code:


Private Sub LBMemberDatasheetForm_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows _
(Me.ListBoxMemberDatasheetForm.ListIndex + 1)

If Me.ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
.TBMemDataAddress1.Text = RowRange.Columns(1).Value
.TBMemDataAddress2.Text = RowRange.Columns(2).Value
.TBMemDataApt.Text = RowRange.Columns(3).Value
.TBMemDataCity.Text = RowRange.Columns(4).Value
.TBMemDataState.Text = RowRange.Columns(5).Value
.TBMemDataZip.Text = RowRange.Columns(6).Value
.TBMemDataPhone.Text = RowRange.Columns(7).Value
.TBMemDataMobile.Text = RowRange.Columns(8).Value
.TBMemDataEmail.Text = RowRange.Columns(9).Value
End With
End If
End Sub

This code works fine, and fast to fill the 9 text boxes with data. i have
another macro that runs when the user clicks ok. this takes the

information
from the textboxes, and back to the record indicated by RowRange:


Private Sub MemDataOKButton_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows

_(ListBoxMemberDatasheetForm.ListIndex
+ 1)

If ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
RowRange.Columns(1).Value = .TBMemDataAddress1.Text
RowRange.Columns(2).Value = .TBMemDataAddress2.Text
RowRange.Columns(3).Value = .TBMemDataApt.Text
RowRange.Columns(4).Value = .TBMemDataCity.Text
RowRange.Columns(5).Value = .TBMemDataState.Text
RowRange.Columns(6).Value = .TBMemDataZip.Text
RowRange.Columns(7).Value = .TBMemDataPhone.Text
RowRange.Columns(8).Value = .TBMemDataMobile.Text
RowRange.Columns(9).Value = .TBMemDataEmail.Text
End With
End If

This macro only works on the first text box. meaning that it only updates
the 1st column in RowRange. if i modify Address2, then click ok, the

textbox
goes back to blank, and does not update the record. please help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Using a form to modify a list

Tom/anyone, why does this work?

"Tom Ogilvy" wrote:

Instead of using rowsource to populate your listbox, use code.

Private sub Userform_Initialize()
Me.ListBoxMemberDatasheetForm.List = Range("Members").Value

' or
'Me.ListBoxMemberDatasheetForm.List = Range("Members").Columns(1).Value
' depending on what is in the listbox
End Sub

--
Regards,
Tom Ogilvy

"Spencer Hutton" wrote in message
...
i have a range of data named members in a worksheet, sheet1. when the
userform loads, a listbox on the form is filled with data from "members".

on
the Click event for the list box, a series of textboxes are filled with

data
from the range "members" by this code:


Private Sub LBMemberDatasheetForm_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows _
(Me.ListBoxMemberDatasheetForm.ListIndex + 1)

If Me.ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
.TBMemDataAddress1.Text = RowRange.Columns(1).Value
.TBMemDataAddress2.Text = RowRange.Columns(2).Value
.TBMemDataApt.Text = RowRange.Columns(3).Value
.TBMemDataCity.Text = RowRange.Columns(4).Value
.TBMemDataState.Text = RowRange.Columns(5).Value
.TBMemDataZip.Text = RowRange.Columns(6).Value
.TBMemDataPhone.Text = RowRange.Columns(7).Value
.TBMemDataMobile.Text = RowRange.Columns(8).Value
.TBMemDataEmail.Text = RowRange.Columns(9).Value
End With
End If
End Sub

This code works fine, and fast to fill the 9 text boxes with data. i have
another macro that runs when the user clicks ok. this takes the

information
from the textboxes, and back to the record indicated by RowRange:


Private Sub MemDataOKButton_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows

_(ListBoxMemberDatasheetForm.ListIndex
+ 1)

If ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
RowRange.Columns(1).Value = .TBMemDataAddress1.Text
RowRange.Columns(2).Value = .TBMemDataAddress2.Text
RowRange.Columns(3).Value = .TBMemDataApt.Text
RowRange.Columns(4).Value = .TBMemDataCity.Text
RowRange.Columns(5).Value = .TBMemDataState.Text
RowRange.Columns(6).Value = .TBMemDataZip.Text
RowRange.Columns(7).Value = .TBMemDataPhone.Text
RowRange.Columns(8).Value = .TBMemDataMobile.Text
RowRange.Columns(9).Value = .TBMemDataEmail.Text
End With
End If

This macro only works on the first text box. meaning that it only updates
the 1st column in RowRange. if i modify Address2, then click ok, the

textbox
goes back to blank, and does not update the record. please help.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Using a form to modify a list

Thanks Tom!

"Tom Ogilvy" wrote:

Instead of using rowsource to populate your listbox, use code.

Private sub Userform_Initialize()
Me.ListBoxMemberDatasheetForm.List = Range("Members").Value

' or
'Me.ListBoxMemberDatasheetForm.List = Range("Members").Columns(1).Value
' depending on what is in the listbox
End Sub

--
Regards,
Tom Ogilvy

"Spencer Hutton" wrote in message
...
i have a range of data named members in a worksheet, sheet1. when the
userform loads, a listbox on the form is filled with data from "members".

on
the Click event for the list box, a series of textboxes are filled with

data
from the range "members" by this code:


Private Sub LBMemberDatasheetForm_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows _
(Me.ListBoxMemberDatasheetForm.ListIndex + 1)

If Me.ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
.TBMemDataAddress1.Text = RowRange.Columns(1).Value
.TBMemDataAddress2.Text = RowRange.Columns(2).Value
.TBMemDataApt.Text = RowRange.Columns(3).Value
.TBMemDataCity.Text = RowRange.Columns(4).Value
.TBMemDataState.Text = RowRange.Columns(5).Value
.TBMemDataZip.Text = RowRange.Columns(6).Value
.TBMemDataPhone.Text = RowRange.Columns(7).Value
.TBMemDataMobile.Text = RowRange.Columns(8).Value
.TBMemDataEmail.Text = RowRange.Columns(9).Value
End With
End If
End Sub

This code works fine, and fast to fill the 9 text boxes with data. i have
another macro that runs when the user clicks ok. this takes the

information
from the textboxes, and back to the record indicated by RowRange:


Private Sub MemDataOKButton_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows

_(ListBoxMemberDatasheetForm.ListIndex
+ 1)

If ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
RowRange.Columns(1).Value = .TBMemDataAddress1.Text
RowRange.Columns(2).Value = .TBMemDataAddress2.Text
RowRange.Columns(3).Value = .TBMemDataApt.Text
RowRange.Columns(4).Value = .TBMemDataCity.Text
RowRange.Columns(5).Value = .TBMemDataState.Text
RowRange.Columns(6).Value = .TBMemDataZip.Text
RowRange.Columns(7).Value = .TBMemDataPhone.Text
RowRange.Columns(8).Value = .TBMemDataMobile.Text
RowRange.Columns(9).Value = .TBMemDataEmail.Text
End With
End If

This macro only works on the first text box. meaning that it only updates
the 1st column in RowRange. if i modify Address2, then click ok, the

textbox
goes back to blank, and does not update the record. please help.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using a form to modify a list

I can only speculate, but when you change data in the rowsource using code,
it can cause some troublesome interactions. I usually disconnect the
rowsource (if I have to have it) and make the change, then reconnect it. As
I recall, Bob Phillips posted a solution a while back that works and doesn't
disconnect the rowsource, but I don't recall what it was.

Someone else may have a better explanation.

--
Regards,
Tom Ogilvy


"Spencer Hutton" wrote in message
...
Tom/anyone, why does this work?

"Tom Ogilvy" wrote:

Instead of using rowsource to populate your listbox, use code.

Private sub Userform_Initialize()
Me.ListBoxMemberDatasheetForm.List = Range("Members").Value

' or
'Me.ListBoxMemberDatasheetForm.List = Range("Members").Columns(1).Value
' depending on what is in the listbox
End Sub

--
Regards,
Tom Ogilvy

"Spencer Hutton" wrote in

message
...
i have a range of data named members in a worksheet, sheet1. when the
userform loads, a listbox on the form is filled with data from

"members".
on
the Click event for the list box, a series of textboxes are filled

with
data
from the range "members" by this code:


Private Sub LBMemberDatasheetForm_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows _
(Me.ListBoxMemberDatasheetForm.ListIndex + 1)

If Me.ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
.TBMemDataAddress1.Text = RowRange.Columns(1).Value
.TBMemDataAddress2.Text = RowRange.Columns(2).Value
.TBMemDataApt.Text = RowRange.Columns(3).Value
.TBMemDataCity.Text = RowRange.Columns(4).Value
.TBMemDataState.Text = RowRange.Columns(5).Value
.TBMemDataZip.Text = RowRange.Columns(6).Value
.TBMemDataPhone.Text = RowRange.Columns(7).Value
.TBMemDataMobile.Text = RowRange.Columns(8).Value
.TBMemDataEmail.Text = RowRange.Columns(9).Value
End With
End If
End Sub

This code works fine, and fast to fill the 9 text boxes with data. i

have
another macro that runs when the user clicks ok. this takes the

information
from the textboxes, and back to the record indicated by RowRange:


Private Sub MemDataOKButton_Click()
Dim RowRange As Range
Set RowRange = Range("Members").Rows

_(ListBoxMemberDatasheetForm.ListIndex
+ 1)

If ListBoxMemberDatasheetForm.ListIndex < -1 Then
With MemberDatasheetForm
RowRange.Columns(1).Value = .TBMemDataAddress1.Text
RowRange.Columns(2).Value = .TBMemDataAddress2.Text
RowRange.Columns(3).Value = .TBMemDataApt.Text
RowRange.Columns(4).Value = .TBMemDataCity.Text
RowRange.Columns(5).Value = .TBMemDataState.Text
RowRange.Columns(6).Value = .TBMemDataZip.Text
RowRange.Columns(7).Value = .TBMemDataPhone.Text
RowRange.Columns(8).Value = .TBMemDataMobile.Text
RowRange.Columns(9).Value = .TBMemDataEmail.Text
End With
End If

This macro only works on the first text box. meaning that it only

updates
the 1st column in RowRange. if i modify Address2, then click ok, the

textbox
goes back to blank, and does not update the record. please help.






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
Trying to modify a list trofie99 Excel Discussion (Misc queries) 1 April 6th 09 02:51 PM
modify drop down list JeanO Excel Discussion (Misc queries) 1 January 7th 09 10:34 PM
Modify Automatic Form Clark Kent[_2_] Excel Discussion (Misc queries) 1 February 22nd 07 07:28 PM
Replace/modify standard data form? Axel Excel Discussion (Misc queries) 3 August 24th 05 02:44 PM
Can I create a FORM (that I can modify etc) from an existing spreadsheet? bruce Excel Programming 0 June 9th 04 09:27 PM


All times are GMT +1. The time now is 11:00 AM.

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"