My Selected print in the list box does not work
- From: Frank Situmorang <FrankSitumorang@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 31 Aug 2009 02:35:01 -0700
Hello,
I appreciate for any help . My select print from the list box does not work,
here is my Module and VBA in the Command button.
The error says when click the command button is unable to call the
module"BuildWhereCondition" , it saya " Expect the valiable not the module.
while all the module and VBA in the command button, I learned from this
forum and I made like it.
This my module and VBA:
Public Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the report
Dim varItem As Variant
Dim strWhereLst As String
Dim ctl As Control
Set ctl = Forms!frmSelectPrint!(strControl) 'replace with your form name
that has the listbox
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhereLst = ""
Case 1 'Only One Selected
strWhereLst = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhereLst = " IN ("
With ctl
For Each varItem In .ItemsSelected
strWhereLst = strWhereLst & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhereLst = Left(strWhereLst, Len(strWhereLst) - 2) & ")"
End Select
This is my command button VBA:
Private Sub SelectedPrint_Click()
Dim strWhere As String
Dim stDocName As String
stDocName = "Update Data Keanggotaan"
strWhere = BuildWhereCondition("Hsehold_listbox") 'this calls the function
and if no items are selected,
' there is no where condition, so all items print, else selected items print
'next line follows the function call:
strWhere = "[Hsehold_listbox] " & strWhere
DoCmd.OpenReport stDocName, acPreview, , strWhere
End Sub
Thanks in advance
Frank
.
- Follow-Ups:
- Prev by Date: Re: Copy record and child records, but not all fields
- Next by Date: Re: My Selected print in the list box does not work
- Previous by thread: Create and Open Word Document From Access & asociate with 2 Fields
- Next by thread: Re: My Selected print in the list box does not work
- Index(es):
Relevant Pages
|