Hi Jeff,
In the tblNotes I have fields as follow:
Contact person, contact phone, (letter 1, letter 2, outbound call 1,
outbound
call 2, outbound call 3, inbound call 1, inbound call 2, next follow up
due,
updated date, hard disc, soft disc - all these fields store the date
action
performed), last payment date, last payment amount, payment arrangement,
promise to pay, legal action, manager comment and collector notes, IDAuto,
batch number, balance
In table Collection I have fields such as : total due, total over 30,
total
over 60, 0-30, 31-60, 61-90, 91-120, >120, bill cycle, IDAuto (for
relationship with other table), batch no, sales, status, Due date
In table Collector I have IDAuto, Agent, Account no, File Type, Customer
Name,
accountKey
The project almost complete using all these table structures, the only one
left is the report.
I usually design the report using wizard tool. I select the rowsource
from
table and it's field. But I try to do it programmatically so the opened
form
will filter the field being displayed in the report.
For example (Collection Form) has criteria as follow:
1. choose file type (3 different file type - using option group))
2. choose Agent (combobox)
3. Choose sort type (current, 30,60, 90, >120, ttl due, follow up due,
account, action)
Based on user selection from Collection Form, I try to create a report
using
SQL statement that select the field.
For example, user choose file type A, Agent, Current)
The field I like to display in report:
Account No, current (0-30), Customer name, Contact phone, contact person,
Notes,
Total 6 fields.
If user choose sort by 60, all column in report will be the same except
the
second one will show (61-90) instead of (0-30)
Below is my code:
Public Sub cmdbtnViewReport_Click()
On Error GoTo Err_cmdbtnViewReport_Click
Dim stDocName As String
Dim strWhere As String
Dim Errorno As String
Dim errormsg As String
stDocName = "ReportCollectionsDashboard"
'strWhere = "[txtAgent] = """ & Me.[cboAgent] & """"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
Exit_cmdbtnViewReport_Click:
Exit Sub
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim Errorno As String
Dim errormsg As String
Dim strSQLtxt As String
lblTitle.Caption = Forms("frmCollections")!lblInfo.Caption
lblReportBillCycle.Caption =
Forms("frmCollections").lblBillCycle.Caption
lblReportTo.Caption = Forms("frmCollections").lblTo.Caption
lblAgent.Caption = Forms("frmCollectionsDashboard")!cboAgent
If Forms("frmCollections")!lblBillCycle.Visible = True Then
lblReportBillCycle.Visible = True
lblReportTo.Visible = True
Else
lblReportBillCycle.Visible = False
lblReportTo.Visible = False
End If
SQLSetup strSQLtxt
Me.RecordSource = strSQLtxt
Exit_Report_Open:
Private Sub SQLSetup(strSQLtxt As String)
On Error GoTo Err_ArborArrivalSQLSetup
Dim Errorno As String
Dim errormsg As String
Select Case Forms("frmCollectionsDashboard")!optgrpSortByOption.Value
Case 1 'Sort By 0-30
strSQLtxt = "SELECT tblAccounts.a_Account,
tblAccounts.a_BillName,
" & _
"tblCollectionsInfo.[CI_Days0-30], & _
"tblCollectorNotes.CN_PersonContacted, " & _
"tblCollectorNotes.CN_ContactPhone, " & _
"tblCollectorNotes.CN_Notes " & _
"FROM (tblAccounts INNER JOIN tblCollectionsInfo "
&
_
"ON tblAccounts.AcctIDAuto = tblCollectionsInfo.
AcctIDAuto) " & _
"INNER JOIN tblCollectorNotes ON tblAccounts.
AcctIDAuto = " & _
"tblCollectorNotes.AcctIDAuto " & _
"WHERE (((tblCollectionsInfo.[CI_Days0-30]) >
0)
" & _
"And ((tblAccounts.Agent) ='" &
lblAgent.Caption
& "')) " & _
"ORDER BY tblCollectionsInfo.[CI_Days0-30]
DESC;"
Case 2 'sort by 31-60
' where will be [CI_Days31-60]
End Select
Exit_SQLSetup:
Exit Sub
I have debug the strSQLtxt statement in the immediate windows, paste it
to
query the table show up okay, so there is no problem with the statement.
But when I run it, it doesn't give me any error, only the detail section
blank, nothing show up.
My question is:
1. When I use the sql statement for the recordsource, do I have to create
unbound text boxes in the details section ( I tried this but it's blank
also)
2. What do I miss or did not do?
3. I read some of the post said ORDER BY clause is ignored in report, how
do
I select the sorting automatically when the report open?
Thank you.
Ges
Jeff said:
I'm still not convinced that the table is well-normalized. It seems to me
that you could use a single field to hold an "action", a single field to
hold a "collector", and a single field to hold "date action was taken",
plus
maybe a rowID field.
If you'll provide a bit more information about the kind of data that is
being stored in these fields, we may be able to offer an easier way. I'm
not trying to be difficult, just pointing out that if your data isn't
structured the way Access expects it to be, you (and Access) will have to
work MUCH harder than you othewise would.
For example, I can use my chainsaw to drive nails ... but it isn't pretty
or
safe or the right tool for the job...<g>
Regards
Jeff Boyce
Microsoft Office/Access MVP
Hi Jeff,
Thanks for the reply. Yes believe it or not but I do have 23 fields in
[quoted text clipped - 38 lines]