Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
For the view All, it's able to run perfect, but when it comes to choosing other variable besides View All, have error instead. I try to solve it since last week. Please Help! Thanks!
Private Sub Command10_Click()
'initalise variable
'categorise FormSelection into variable choiceDim choice As String
If (FormSelection.Value = "Vendor") Then
choice = "A"
ElseIf (FormSelection.Value = "Inhouse") Then
choice = "B"
ElseIf (FormSelection.Value = "Japan") Then
choice = "C"
End IfOn Error GoTo Err_Command10_Click
Dim stDocName As String
stDocName = "ProductRpt"
'>> Total of 4 combinations <<
'Category Name = view all Form Selection = view all
If (CateName.Value = "View All" And FormSelection.Value = "View All") Then
DoCmd.OpenReport stDocName, acPreview
'Category Name = view all Form Selection != view all
ElseIf (CateName.Value = "View All" And FormSelection.Value <> "View All") Then
DoCmd.OpenReport stDocName, acPreview, , "FormSelection = " & choice
'Category Name != view all Form Selection = view all
ElseIf (CateName.Value <> "View All" And FormSelection.Value = "View All") Then
'Category Name! = view all Form Selection != view all
DoCmd.OpenReport stDocName, acPreview, , "CateName =" & CateName.Value
Else
'rest is team and criteria
DoCmd.OpenReport stDocName, acPreview, , "CateName = '" & CateName.Value & _
"' and FormSelection = " & choice
End If
Exit_Command10_Click:
Exit SubErr_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click
End SubPrivate Sub FormSelection_AfterUpdate()
'not one of the choice in DDL
'not view not outstanding not completed
If (FormSelection.Value = "View all") Then
ElseIf (FormSelection.Value = "Vendor") Then
ElseIf (FormSelection.Value = "Inhouse") Then
ElseIf (FormSelection.Value = "Japan") Then
Else
FormSelection.Value = "View all"
End If
End Sub

It is still the same. When run, i choose in a different variable that is provided in the drop down list, it shows all the records but not the specific record i want. Also, it keep poping out a Msg box with a heading saying" parameter value" And i've to key in something before it can proceed to showing the record. Thanks btw. (:

dim choice as string ...... 'Category Name = view all Form Selection != view all ElseIf (CateName.Value = "View All" And FormSelection.Value <> "View All") Then DoCmd.OpenReport stDocName, acPreview, , "FormSelection = " & choicechoice is of string datatype, when filtering, you have to put quotes around any string:
DoCmd.OpenReport stDocName, acPreview, , "FormSelection = """ & choice & """"and what happened if choice is null/empty??

Thanks so much for the reply. I implement the coding you gave me and made amendments. But still, when changing the variables for CateName, and FormSelection View All, it shows all the records regardless it is relevant or not.
When i change variables for FormSelection and CatName stick with View All, no record was shown.
If choice is nothing, there would be an error?

![]() |
VB script to put time and...
|
Folder Name & Number of F...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |