Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default list index problem

In the following code I'm trying to pass a variable value from one form
to another another form using the list index function, first off can
this be done?

Ultimately I need to populate the second form with data from the same
row in the worksheet that the first form looked at. I was hoping to
simply use the offset command to select the appropriate cells in the
worksheet to populate all the text boxes in the second user form.

please see the following code, the code runs fine it dispays the first
user form, allows selection of a part no, the msg box displays the
appropriate product code, the last user form is shown depending upon
the product code, but the text boxes are empty, nothing shown. Whats
going wrong. Does the list index lose it's focus when passing from one
form to another, how can this be overcome.

Thanks
burl_rfc

--------------------------------------------------------------------------

this allows the user to select the part no. using part no. form


Private Sub Userform_Initialize() 'Get Part Number Form
Dim SourceWB As Workbook
Dim myRng As Range


With Me.ComboBox1
.ColumnCount = 2
.ColumnWidths = "12;0" 'hide the second column
.Clear
Set SourceWB = Workbooks.Open("C:\MyFolder\MyWorkbook.xls",
False, True)
With SourceWB.Worksheets(1)
Set myRng = .Range("A3:B" & .Cells(.Rows.Count,
"A").End(xlUp).Row)
End With
.List = myRng.Value
SourceWB.Close False
End With
End Sub


-------------------------------------------------------------------------

this sub will re-direct the user to the appropriate user form depending

upon the product code
in the adjacent cell to the part number (same row but in column B)


'Option Explicit


Dim myVar As Variant 'String/Long/double???


With Me.ComboBox1
If .ListIndex -1 Then
myVar = .List(.ListIndex, 1) '<-- second column!
MsgBox myVar 'for testing only
Select Case myVar
Case Is = "Metal"
frmMetalQuoteForm.Show
Case Is = "Glass"
frmGlassQuoteForm.Show
End Select
End If
End With
End Sub


---------------------------------------------------------------------------*--

this is one of the forms that requires loading with data


Private Sub Userform_Initialize() 'Metals Quote Form
myVar1 = .List(.ListIndex, 0)
myVar2 = .List(.Listindex, 1)
myVar3 = .List(.Listindex, 2)


frmMetalQuoteForm.txtQuote.Value = myVar1
frmMetalQuoteForm.txtQuote.Value = myVar2
frmMetalQuoteForm.txtQuote.Value = myVar3


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default list index problem

Private Sub Userform_Initialize() 'Metals Quote Form

with NameofFirstForm.Combobox1
myVar1 = .List(.ListIndex, 0)
myVar2 = .List(.Listindex, 1)
' the list only has two columns, so next
' line is a no go
'myVar3 = .List(.Listindex, 2)
End With

frmMetalQuoteForm.txtQuote.Value = myVar1
frmMetalQuoteForm.txtQuote.Value = myVar2
frmMetalQuoteForm.txtQuote.Value = myVar3


End Sub


--
Regards,
Tom Ogilvy

"burl_rfc" wrote in message
oups.com...
In the following code I'm trying to pass a variable value from one form
to another another form using the list index function, first off can
this be done?

Ultimately I need to populate the second form with data from the same
row in the worksheet that the first form looked at. I was hoping to
simply use the offset command to select the appropriate cells in the
worksheet to populate all the text boxes in the second user form.

please see the following code, the code runs fine it dispays the first
user form, allows selection of a part no, the msg box displays the
appropriate product code, the last user form is shown depending upon
the product code, but the text boxes are empty, nothing shown. Whats
going wrong. Does the list index lose it's focus when passing from one
form to another, how can this be overcome.

Thanks
burl_rfc

--------------------------------------------------------------------------

this allows the user to select the part no. using part no. form


Private Sub Userform_Initialize() 'Get Part Number Form
Dim SourceWB As Workbook
Dim myRng As Range


With Me.ComboBox1
.ColumnCount = 2
.ColumnWidths = "12;0" 'hide the second column
.Clear
Set SourceWB = Workbooks.Open("C:\MyFolder\MyWorkbook.xls",
False, True)
With SourceWB.Worksheets(1)
Set myRng = .Range("A3:B" & .Cells(.Rows.Count,
"A").End(xlUp).Row)
End With
.List = myRng.Value
SourceWB.Close False
End With
End Sub


-------------------------------------------------------------------------

this sub will re-direct the user to the appropriate user form depending

upon the product code
in the adjacent cell to the part number (same row but in column B)


'Option Explicit


Dim myVar As Variant 'String/Long/double???


With Me.ComboBox1
If .ListIndex -1 Then
myVar = .List(.ListIndex, 1) '<-- second column!
MsgBox myVar 'for testing only
Select Case myVar
Case Is = "Metal"
frmMetalQuoteForm.Show
Case Is = "Glass"
frmGlassQuoteForm.Show
End Select
End If
End With
End Sub


---------------------------------------------------------------------------*
--

this is one of the forms that requires loading with data


Private Sub Userform_Initialize() 'Metals Quote Form
myVar1 = .List(.ListIndex, 0)
myVar2 = .List(.Listindex, 1)
myVar3 = .List(.Listindex, 2)


frmMetalQuoteForm.txtQuote.Value = myVar1
frmMetalQuoteForm.txtQuote.Value = myVar2
frmMetalQuoteForm.txtQuote.Value = myVar3


End Sub


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
Dependent List "Index" Problem Benjamin Excel Worksheet Functions 2 June 13th 09 05:36 PM
Index Problem Tracey Excel Worksheet Functions 5 February 1st 08 10:27 PM
=Index Problem Nikki Excel Discussion (Misc queries) 5 September 30th 07 11:18 PM
INDEX PROBLEM...I THINK Steve Excel Worksheet Functions 15 February 20th 07 09:28 PM
INDEX problem malik641 Excel Worksheet Functions 7 July 7th 05 01:50 PM


All times are GMT +1. The time now is 01:41 PM.

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

About Us

"It's about Microsoft Excel"