Hi. I really need help.
The issue is that I have a form that is utilized as a 'search for' various values and returns the values into a report.
The report is functioning fine, however, I am having a really hard time building a 'sort by' function that will pass to the report to sort by the values selected.
For instance, I have 4 check boxes:
1) Coordinator, 2) Sales Number 3) City 4) Office location
The issue that I am having is that the sort function I placed into either the 'onclick' function to pull the report or on the 'onopen' function of the report, I cant seem to get the sort to work, at all.
Here is the code:
Private Sub sort1_sub()
If Me.chkcoord = True Then
gstSqlSort0 = "me.Coordinator"
Else
gstSqlSort0 = Me.chkcoord
End If
If Not IsNull(chkcoord) Then
If chksales = True Then
gstSqlSort1 = "Sales #"
Else
gstSqlSort1 = chksales
End If
End If
If Not IsNull(chkjobcode) Then
If chkjobcode = True Then
gstSqlSort2 = "Job Code"
Else
gstSqlSort2 = JobCode
End If
End If
If Not IsNull(chkflc) Then
If chkflc = True Then
gstSqlSort3 = "Job Code"
Else
gstSqlSort3 = JobCode
End If
End If
If Not IsNull(chkcust) Then
If JobCode = True Then
gstSqlSort4 = "CUSTOMER NAME"
Else
gstSqlSort4 = chkcust
End If
End If
gstSqlOrderBy = " Sort By " & gstSqlSort0
If gstSqlSort1 <> "" Then
'gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort1
'End If
If gstSqlSort2 <> "" Then
gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort2
End If
If gstSqlSort3 <> "" Then
gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort3
End If
If gstSqlSort4 <> "" Then
gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort4
End If
End Sub
Which, is called when I click on the report button (the code
Private Sub btnReportWriterPreview_Click()
On Error GoTo Err_btnReportWriterPreview_Click
gstsqlqry = "select QryMainSPSR.* from QryMainSPSR"
sort1_sub
Dim stDocName As String
stDocName = "RptPMSPSR"
DoCmd.OpenReport stDocName, acPreview
Exit_btnReportWriterPreview_Click:
Exit Sub
Err_btnReportWriterPreview_Click:
MsgBox Err.Description
Resume Exit_btnReportWriterPreview_Click
End Sub
The issue is that I have a form that is utilized as a 'search for' various values and returns the values into a report.
The report is functioning fine, however, I am having a really hard time building a 'sort by' function that will pass to the report to sort by the values selected.
For instance, I have 4 check boxes:
1) Coordinator, 2) Sales Number 3) City 4) Office location
The issue that I am having is that the sort function I placed into either the 'onclick' function to pull the report or on the 'onopen' function of the report, I cant seem to get the sort to work, at all.
Here is the code:
Private Sub sort1_sub()
If Me.chkcoord = True Then
gstSqlSort0 = "me.Coordinator"
Else
gstSqlSort0 = Me.chkcoord
End If
If Not IsNull(chkcoord) Then
If chksales = True Then
gstSqlSort1 = "Sales #"
Else
gstSqlSort1 = chksales
End If
End If
If Not IsNull(chkjobcode) Then
If chkjobcode = True Then
gstSqlSort2 = "Job Code"
Else
gstSqlSort2 = JobCode
End If
End If
If Not IsNull(chkflc) Then
If chkflc = True Then
gstSqlSort3 = "Job Code"
Else
gstSqlSort3 = JobCode
End If
End If
If Not IsNull(chkcust) Then
If JobCode = True Then
gstSqlSort4 = "CUSTOMER NAME"
Else
gstSqlSort4 = chkcust
End If
End If
gstSqlOrderBy = " Sort By " & gstSqlSort0
If gstSqlSort1 <> "" Then
'gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort1
'End If
If gstSqlSort2 <> "" Then
gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort2
End If
If gstSqlSort3 <> "" Then
gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort3
End If
If gstSqlSort4 <> "" Then
gstSqlOrderBy = gstSqlOrderBy & "," & gstSqlSort4
End If
End Sub
Which, is called when I click on the report button (the code
Private Sub btnReportWriterPreview_Click()
On Error GoTo Err_btnReportWriterPreview_Click
gstsqlqry = "select QryMainSPSR.* from QryMainSPSR"
sort1_sub
Dim stDocName As String
stDocName = "RptPMSPSR"
DoCmd.OpenReport stDocName, acPreview
Exit_btnReportWriterPreview_Click:
Exit Sub
Err_btnReportWriterPreview_Click:
MsgBox Err.Description
Resume Exit_btnReportWriterPreview_Click
End Sub