Help w/ VBA lstBox and SubForms

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
 
D

Dan Artuso

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top