S
S Jackson
I have created a multi-select list box. After the user makes his
selections, he presses okay. I am trying to open up a form collecting only
the data as specified by the user per his selections. Someone was kind to
reply as follows:
You'll need to loop through the listbox's ItemsSelected collection,
building up an IN clause in a SQL string: e.g.
Private Sub OkBtn_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim varItem As Variant
stDocName = "frmMasterall"
stLinkCriteria = "[Region] IN ("
For Each varItem In Me.RegionList.ItemsSelected
stLinkCriteria = stLinkCriteria & _
Me.Regionlist.ItemData(varItem) & ","
Next varItem
strLinkCriteria = Left(strLinkCriteria, Len(strLinkCriteria) - 1 _
& ")"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
Unfortunately, when I try to type in this code in VB, I get an Invalid
Character error when I attempt to type the last line:
strLinkCriteria = Left(strLinkCriteria, Len(strLinkCriteria) - 1 _
VB doesn't like the _
Sorry, I know you shouldn't use code unless you understand it, but I'm
floundering here. I have no books, no nothing. Only MS help files which
are useless and a deadline to get this done. I tend to learn better by
"doing" anyway rather than by "reading."
Any help is very much appreciated!
selections, he presses okay. I am trying to open up a form collecting only
the data as specified by the user per his selections. Someone was kind to
reply as follows:
You'll need to loop through the listbox's ItemsSelected collection,
building up an IN clause in a SQL string: e.g.
Private Sub OkBtn_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim varItem As Variant
stDocName = "frmMasterall"
stLinkCriteria = "[Region] IN ("
For Each varItem In Me.RegionList.ItemsSelected
stLinkCriteria = stLinkCriteria & _
Me.Regionlist.ItemData(varItem) & ","
Next varItem
strLinkCriteria = Left(strLinkCriteria, Len(strLinkCriteria) - 1 _
& ")"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
Unfortunately, when I try to type in this code in VB, I get an Invalid
Character error when I attempt to type the last line:
strLinkCriteria = Left(strLinkCriteria, Len(strLinkCriteria) - 1 _
VB doesn't like the _
Sorry, I know you shouldn't use code unless you understand it, but I'm
floundering here. I have no books, no nothing. Only MS help files which
are useless and a deadline to get this done. I tend to learn better by
"doing" anyway rather than by "reading."
Any help is very much appreciated!