473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Report errors from a form to select names and dates with...

Greetings Gurus,

In a report showing the names of students and their progress, I am
getting an error in the name field (Name: #Error). The report gets its
data from an unbound form containing two unbound textboxes,
"txtStartDate" and "txtEndDate," and a multi-select listbox,
"listName." I think the error occurs when there is no correct
combination of data--for instance, no records for John Doe entered
during this past week.

This is my 1st attempt at making a form allowing a user to set multiple
criteria. I've tried to adapt code from Allen Browne's site and other
posts, but don't really know what I'm doing. I'd like for users to
select mutliple students (or ALL students) from the listbox and specify
a date range (which isn't required).

The report's name is rptProgressReports.
The form's name is frmSelectReport.
The listbox's name is listname.
The listbox's row source is
SELECT Students.StudentID, Students.LastName, Students.FirstName FROM
Students ORDER BY Students.LastName;

The command button's on click event is:

On Error GoTo Err_cmdOK_Click

Dim i As Integer
Dim stDocName As String
Dim stWhere As String
Dim sTest As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"

stDocName = "rptProgressReports"

For i = 0 To listName.ItemsSelected.Count - 1
If stWhere <> "" Then stWhere = stWhere & ", "
stWhere = stWhere & listName.Column(0, listName.ItemsSelected(i))
Next

strDate = "Date" 'Date is the name of field in the detail section
of the report.

If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
sTest = strDate & " < " & Format(Me.txtEndDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
sTest = strDate & " > " & Format(Me.txtStartDate,
conDateFormat)
Else 'Both start and end dates.
sTest = strDate & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If

If stWhere <> "" Then
If sTest <> "" Then sTest = sTest & " AND "
sTest = sTest & "StudentID IN (" & stWhere & ")"
End If

DoCmd.OpenReport stDocName, acViewPreview, , sTest

Exit_cmdOK_Click:
Exit Sub

Err_cmdOK_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_cmdOK_Click
End Sub

An example of the filter that was input into the Report's filter is:
(Date Between #01/23/2006# And #01/29/2006# AND StudentID IN (7))
The record source of the report is a query containing StudentID,
LastName, FirstName, ProgressID, Progress, Date, ClassID, and Class.

In terms of selecting ALL students from the listbox, is it possible to
do this with a union query involving multiple columns in the listbox?

Thanks,

Arnold

Jan 29 '06 #1
2 1768
Your first problem is that DATE is a reserved word in MSAccess.
(Date Between #01/23/2006# And #01/29/2006#
AND StudentID IN (7))

you also say 'Date is the name of field in the detail
section of the report'
It's the name of the field in the query underlying the report
that you need to use. It's not clear that they are the same, if
not, adjust accordingly.
The answer to the question about adding "< ALL Sudents > to a
listbox is YES.

Q

"Arnold" <ee*******@kc.rr.com> wrote in
news:11*********************@g43g2000cwa.googlegro ups.com:
Greetings Gurus,

In a report showing the names of students and their progress,
I am getting an error in the name field (Name: #Error). The
report gets its data from an unbound form containing two
unbound textboxes, "txtStartDate" and "txtEndDate," and a
multi-select listbox, "listName." I think the error occurs
when there is no correct combination of data--for instance, no
records for John Doe entered during this past week.

This is my 1st attempt at making a form allowing a user to set
multiple criteria. I've tried to adapt code from Allen
Browne's site and other posts, but don't really know what I'm
doing. I'd like for users to select mutliple students (or ALL
students) from the listbox and specify a date range (which
isn't required).

The report's name is rptProgressReports.
The form's name is frmSelectReport.
The listbox's name is listname.
The listbox's row source is
SELECT Students.StudentID, Students.LastName,
Students.FirstName FROM Students ORDER BY Students.LastName;

The command button's on click event is:

On Error GoTo Err_cmdOK_Click

Dim i As Integer
Dim stDocName As String
Dim stWhere As String
Dim sTest As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"

stDocName = "rptProgressReports"

For i = 0 To listName.ItemsSelected.Count - 1
If stWhere <> "" Then stWhere = stWhere & ", "
stWhere = stWhere & listName.Column(0,
listName.ItemsSelected(i)) Next

strDate = "Date" 'Date is the name of field in the detail
section of the report.

If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no
start.
sTest = strDate & " < " &
Format(Me.txtEndDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but
no End.
sTest = strDate & " > " &
Format(Me.txtStartDate,
conDateFormat)
Else 'Both start and end dates.
sTest = strDate & " Between " &
Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate,
conDateFormat)
End If
End If

If stWhere <> "" Then
If sTest <> "" Then sTest = sTest & " AND "
sTest = sTest & "StudentID IN (" & stWhere & ")"
End If

DoCmd.OpenReport stDocName, acViewPreview, , sTest

Exit_cmdOK_Click:
Exit Sub

Err_cmdOK_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_cmdOK_Click
End Sub

An example of the filter that was input into the Report's
filter is: (Date Between #01/23/2006# And #01/29/2006# AND
StudentID IN (7)) The record source of the report is a query
containing StudentID, LastName, FirstName, ProgressID,
Progress, Date, ClassID, and Class.

In terms of selecting ALL students from the listbox, is it
possible to do this with a union query involving multiple
columns in the listbox?

Thanks,

Arnold


--
Bob Quintal

PA is y I've altered my email address.
Jan 29 '06 #2
Thanks for the tip. I renamed the controls that were simply "date."

However, this didn't fix the problem where if a student is selected
from the listbox on the form, but no progress records were previously
entered for that student, the report generates but with an error for
the name's field.

Any other ideas?--all are greatly appreciated. Thanks.

Jan 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
4
by: No Spam | last post by:
Dear Access 2000 users, I have a crosstab query that puts together certain information perfectly. It has a criteria that is based on a form that limits how many columns are returned based on...
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
1
by: prabhukalyan | last post by:
Hi all, I am not so good in queries. here is my problem 2 tables to store the received items (fabric)-- inwardmaster, inwarddetails and after some processing (Dyeing) the items were...
5
by: sara | last post by:
I have reports that run from a form where the user can choose a date range, or they run automatically for a week in the "Weekly Reports" option. I created 2 queries and 2 reports - one query...
0
by: Bill | last post by:
I've searched comp.databases.ms-access for a solution and found help but still haven't got my problem solved. I want to record weekly attendance and print an attendance "check off" sheet where...
8
by: sara | last post by:
Hi - I have looked at all posts and tried both Allen Browne's Report Sorting at run Time ( Select Case Forms!frmChooseSort!grpSort Case 1 'Name Me.GroupLevel(0).ControlSource = "LastName"...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.