vaibhav2015
Registered User.
- Local time
- Today, 23:52
- Joined
- Sep 15, 2015
- Messages
- 25
Hi,
I am not expert in VBA codes. I have used below VBA codes as per my query.
I have one query named "Material_List" where I have list of material(text field) and that I want to add in Form in text box with multiselect (simple) option.
I have another query named "Plant_ACT" where I have all data related to material numbers.
I want to do below action in form :-
when I select multiple material numbers and click Preview, that report or query must extract the data whatever I selected in Form in Material list text box.
Please advice.
Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list box.
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
strDelim = """" 'Delimiter appropriate to field type. See note 1.
strDoc = "Material list"
'Loop through the ItemsSelected in the list box.
With Me.Mat_list
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = ItemData(varItem) & strDelim & ","
End If
Next
End With
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Material] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Material: " & Left$(strDescrip, lngLen)
End If
End If
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdPreview_Click"
End If
Resume Exit_Handler
End Sub
I am not expert in VBA codes. I have used below VBA codes as per my query.
I have one query named "Material_List" where I have list of material(text field) and that I want to add in Form in text box with multiselect (simple) option.
I have another query named "Plant_ACT" where I have all data related to material numbers.
I want to do below action in form :-
when I select multiple material numbers and click Preview, that report or query must extract the data whatever I selected in Form in Material list text box.
Please advice.
Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the list box.
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.
strDelim = """" 'Delimiter appropriate to field type. See note 1.
strDoc = "Material list"
'Loop through the ItemsSelected in the list box.
With Me.Mat_list
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = ItemData(varItem) & strDelim & ","
End If
Next
End With
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[Material] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Material: " & Left$(strDescrip, lngLen)
End If
End If
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdPreview_Click"
End If
Resume Exit_Handler
End Sub