Help w/ VBA lstBox and SubForms

  • Thread starter Thread starter J.
  • Start date Start date
J

J.

Hello Everyone,

I'm new, so please be patient. I have a list box that is populated by a
test string. It's constant, so it never changes. My form has a
subform in it. I want to display a different subform for each lstIndex
of the lstBox. I'm perplexed. This is what I have tried:

'this is the strings
Const strText = "Test1, Test2" 'initialize string

Private Sub Form_Open(Cancel As Integer)
'fill the listbox, THIS WORKS!
lstItems.RowSource = strText
End Sub

Private Sub lstItems_Click()
'Change sub-form recordsource
If lstItems.ListIndex = 1 Then
'load
subFormFrame.Source = DoCmd.OpenForm("SubForm1", acFormView)
Else
'load
subFormFrame.Source = DoCmd.OpenForm("SubForm2", acFormView)
End If
End Sub

Any help for this newbie would be appreciated!

J
 
Hi,
Try something like this in the AfterUpdate event of your listbox

Private Sub lstItems_AfterUpdate()
'Change sub-form recordsource
If lstItems = "Test1" Then
'load
subFormFrame.SourceObject = "SubForm1"
Else
'load
subFormFrame.SourceObject = "SubForm2"
End If
End Sub
 
Back
Top