Coustom Reports

  • Thread starter Thread starter Daniel V
  • Start date Start date
D

Daniel V

Hello,

Atm I am running reports by selecting a drop down froma from, but
I want to achieve this :

To obtain reports by selecting different checkmarks (YES/NO) from a form and
then by clicking on a button to get the desired report. Any ideas ?

Thanks,
Dan
 
Daniel,

I don't know what your experience is, but if you know VBA and how to build a
where clause for a report, you build it based on the Yes values of the
Checkboxes, similar to this:

Dim strWhere as String
If chkBox1 = True then
strWhere = <whatever your condtions are>
End If

If chkBox2 = True then
strWhere = strWhere & " And <whatever your condtions are>
End If

If chkBox3 = True then
strWhere = strWhere & " And <whatever your condtions are>End If

If chkBox4 = True then
strWhere = strWhere & " And <whatever your condtions are>End If

If chkBox5 = True then
strWhere = strWhere & " And <whatever your condtions are>
End If

Then strip out the trialing " And"

If Left(strWhere , 4) = " And" Then
strWhere = Mid(strWhere , 6, Len(strWhere ))
End If

The open the report with the where clause like:
DoCmd.OpenReport "SomeReport", , , strCriteria

This is just a rough example. You need to work it out according to your own
specification, but that is basically how it is done.

Below is a working example of building a where clause. In the example it
is the variable, strCriteria. [optShipped] is an option group with a value
of 1, 2, or 3, which is similar to a checkbox. I hope this helps you. I
couldn't find an example with check box usage.


*********** Start Code example
Private Sub OK_Click()

On Error GoTo error_Section

DoCmd.SetWarnings False
'replaces query _SumProducts with a table by the same name becuase of a
problem with
'query _ProductsRemaining delivering a Invalid Procedure error.
DoCmd.OpenQuery "_SumProductsMakeTable"
'replaces query _SumProductsShipped with a table by the same name becuase
of a problem with
'query _ProductsRemaining delivering a Invalid Procedure error.
DoCmd.OpenQuery "_SumProductsShippedMakeTable"
DoCmd.SetWarnings True



Dim strProds As String
Dim iPrintType As Integer

If [ShowProducts] = True Then 'Designates which report to run
strProds = " w/ Prods"
Else
strProds = " w/o Prods"
End If

If [Preview] = 0 Then
iPrintType = 0
Else
iPrintType = 2
End If

If IsNull([Date1]) And IsNull([Date2]) And (IsNull([Cust]) Or [Cust] = "")
Then
DoCmd.OpenReport "UnInvoiced Orders List", acViewNormal
'MsgBox "Report 1"
Exit Sub
End If

Dim strCriteria As String


If getDateType() = "ordDate" Then
If Not IsNull([Date1]) Then
strCriteria = "[OrdDate] >= #" & [Date1] & "#"
End If

If Not IsNull([Date2]) Then
strCriteria = strCriteria & " And [OrdDate] <= #" & [Date2] & "#"
End If
ElseIf getDateType() = "ordShipDate" Then
If Not IsNull([Date1]) Then
strCriteria = "[ordShipDate] >= #" & [Date1] & "#"
End If

If Not IsNull([Date2]) Then
strCriteria = strCriteria & " And [ordShipDate] <= #" & [Date2] & "#"
End If
Else
If Not IsNull([Date1]) Then
strCriteria = "[OrdDate] >= #" & [Date1] & "#"
End If

If Not IsNull([Date2]) Then
strCriteria = strCriteria & " And [OrdDate] <= #" & [Date2] & "#"
End If

End If


If Not IsNull([Cust]) Then
strCriteria = strCriteria & " And [ordCustID] = " & [Cust]
End If

If [optShipped] = 2 Then 'Filter for 1) Shipped or 2) Unshipped
strCriteria = strCriteria & " And [Shipped Complete] = " & True
ElseIf [optShipped] = 3 Then
strCriteria = strCriteria & " And [Shipped Complete] = " & False
End If


If Left(strCriteria, 4) = " And" Then
strCriteria = Mid(strCriteria, 6, Len(strCriteria))
End If

If [chkLocationGrouping] = True Then
If [Location] <> "All" Then
strCriteria = strCriteria & " And [Location] = '" & [Location] & "'"
If Left(strCriteria, 4) = " And" Then
strCriteria = Mid(strCriteria, 6, Len(strCriteria))
End If
DoCmd.OpenReport "UnInvoiced Orders List" & strProds & " by Loc",
iPrintType, , strCriteria
'MsgBox "Report 2"
Else
DoCmd.OpenReport "UnInvoiced Orders List" & strProds & " by Loc",
iPrintType, , strCriteria
'MsgBox "Report 3"
End If
Else
DoCmd.OpenReport "UnInvoiced Orders List" & strProds, iPrintType, ,
strCriteria
'MsgBox "Report 4"
End If

exit_Section:
DoCmd.SetWarnings True
Exit Sub
error_Section:
If Err = 2501 Then
Resume Next
Else
DoCmd.SetWarnings True
MsgBox "Error " & Err & "; " & Err.Description
GoTo exit_Section
End If


End Sub


*********** End Code example

God Bless,

Mark A. Sam
 
Thans a lot, you gave the idea where to start from .

Daniel

Mark A. Sam said:
Daniel,

I don't know what your experience is, but if you know VBA and how to build a
where clause for a report, you build it based on the Yes values of the
Checkboxes, similar to this:

Dim strWhere as String
If chkBox1 = True then
strWhere = <whatever your condtions are>
End If

If chkBox2 = True then
strWhere = strWhere & " And <whatever your condtions are>
End If

If chkBox3 = True then
strWhere = strWhere & " And <whatever your condtions are>End If

If chkBox4 = True then
strWhere = strWhere & " And <whatever your condtions are>End If

If chkBox5 = True then
strWhere = strWhere & " And <whatever your condtions are>
End If

Then strip out the trialing " And"

If Left(strWhere , 4) = " And" Then
strWhere = Mid(strWhere , 6, Len(strWhere ))
End If

The open the report with the where clause like:
DoCmd.OpenReport "SomeReport", , , strCriteria

This is just a rough example. You need to work it out according to your own
specification, but that is basically how it is done.

Below is a working example of building a where clause. In the example it
is the variable, strCriteria. [optShipped] is an option group with a value
of 1, 2, or 3, which is similar to a checkbox. I hope this helps you. I
couldn't find an example with check box usage.


*********** Start Code example
Private Sub OK_Click()

On Error GoTo error_Section

DoCmd.SetWarnings False
'replaces query _SumProducts with a table by the same name becuase of a
problem with
'query _ProductsRemaining delivering a Invalid Procedure error.
DoCmd.OpenQuery "_SumProductsMakeTable"
'replaces query _SumProductsShipped with a table by the same name becuase
of a problem with
'query _ProductsRemaining delivering a Invalid Procedure error.
DoCmd.OpenQuery "_SumProductsShippedMakeTable"
DoCmd.SetWarnings True



Dim strProds As String
Dim iPrintType As Integer

If [ShowProducts] = True Then 'Designates which report to run
strProds = " w/ Prods"
Else
strProds = " w/o Prods"
End If

If [Preview] = 0 Then
iPrintType = 0
Else
iPrintType = 2
End If

If IsNull([Date1]) And IsNull([Date2]) And (IsNull([Cust]) Or [Cust] = "")
Then
DoCmd.OpenReport "UnInvoiced Orders List", acViewNormal
'MsgBox "Report 1"
Exit Sub
End If

Dim strCriteria As String


If getDateType() = "ordDate" Then
If Not IsNull([Date1]) Then
strCriteria = "[OrdDate] >= #" & [Date1] & "#"
End If

If Not IsNull([Date2]) Then
strCriteria = strCriteria & " And [OrdDate] <= #" & [Date2] & "#"
End If
ElseIf getDateType() = "ordShipDate" Then
If Not IsNull([Date1]) Then
strCriteria = "[ordShipDate] >= #" & [Date1] & "#"
End If

If Not IsNull([Date2]) Then
strCriteria = strCriteria & " And [ordShipDate] <= #" & [Date2] & "#"
End If
Else
If Not IsNull([Date1]) Then
strCriteria = "[OrdDate] >= #" & [Date1] & "#"
End If

If Not IsNull([Date2]) Then
strCriteria = strCriteria & " And [OrdDate] <= #" & [Date2] & "#"
End If

End If


If Not IsNull([Cust]) Then
strCriteria = strCriteria & " And [ordCustID] = " & [Cust]
End If

If [optShipped] = 2 Then 'Filter for 1) Shipped or 2) Unshipped
strCriteria = strCriteria & " And [Shipped Complete] = " & True
ElseIf [optShipped] = 3 Then
strCriteria = strCriteria & " And [Shipped Complete] = " & False
End If


If Left(strCriteria, 4) = " And" Then
strCriteria = Mid(strCriteria, 6, Len(strCriteria))
End If

If [chkLocationGrouping] = True Then
If [Location] <> "All" Then
strCriteria = strCriteria & " And [Location] = '" & [Location] & "'"
If Left(strCriteria, 4) = " And" Then
strCriteria = Mid(strCriteria, 6, Len(strCriteria))
End If
DoCmd.OpenReport "UnInvoiced Orders List" & strProds & " by Loc",
iPrintType, , strCriteria
'MsgBox "Report 2"
Else
DoCmd.OpenReport "UnInvoiced Orders List" & strProds & " by Loc",
iPrintType, , strCriteria
'MsgBox "Report 3"
End If
Else
DoCmd.OpenReport "UnInvoiced Orders List" & strProds, iPrintType, ,
strCriteria
'MsgBox "Report 4"
End If

exit_Section:
DoCmd.SetWarnings True
Exit Sub
error_Section:
If Err = 2501 Then
Resume Next
Else
DoCmd.SetWarnings True
MsgBox "Error " & Err & "; " & Err.Description
GoTo exit_Section
End If


End Sub


*********** End Code example

God Bless,

Mark A. Sam




Daniel V said:
Hello,

Atm I am running reports by selecting a drop down froma from, but
I want to achieve this :

To obtain reports by selecting different checkmarks (YES/NO) from a form
and
then by clicking on a button to get the desired report. Any ideas ?

Thanks,
Dan
 
Back
Top