473,513 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Include all data in listbox to a report

1 New Member
Hi All, I'm new here as well as my knowledge about Microsoft access vba .

I have a form. In my form, I have two text box that will get the start date and the end date and a button that will query the data to my sql. Then the data will be shown in listbox. What I want is that the ALL the data in the listbox will be displayed in the report without selecting one by one. Is it possible?

please help :)
Feb 15 '18 #1
7 1628
gnawoncents
214 New Member
Hi, Hacking, and welcome to Bytes! If I'm understanding correctly, the user will input a start and end date, and you want to generate a report of records between those dates. The easiest way, depending on your current setup, should be to use the dates to filter the report's source records as you open the report. Something like the following should get you started:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "YourReportName", acViewPreview, , "fldDate BETWEEN #" & Me.txtStartDate & "# AND #" & Me.txtEndDate & "#"
  2.  
Where
YourReportName = the name of the target report to filter and open
fldDate = the field in your source table that has the dates to search through
txtStartDate = the name of the textbox on the form used to enter the start date
txtEndDate = the name of the textbox on the form used to enter the end date

Of course this will only work if my assumptions about your current construct are correct. Otherwise, you can use this as a starting point or provide more detailed information, and we can help you work toward a better answer.
Feb 15 '18 #2
NeoPa
32,557 Recognized Expert Moderator MVP
We get a lot of very helpful posts on here that are nevertheless careless of how properly to deal with dates in SQL (Literal DateTimes and Their Delimiters (#)). It works fine in the States but for the rest of the world it causes many problems which are very difficult to determine or debug. Dealing with date literals in SQL is most emphatically NOT about simply dropping the default display into a SQL string with hashes (#) around them.

Don't get me wrong. GnawOnCents' post is very helpful, and they're a very valued and appreciated member of our community. It's simply that not all members are aware of issues that occur only outside of the USA.

So, if you want to write reliable and portable code, or even simply happen to live outside of the USA, then you'd be well advised to ensure your date literals are handled more robustly.

@Hacking01
I see you're new. Welcome to Bytes.

Experience tells me that members get more help and sympathy when their posts are prepared with care, rather than thrown together in haste. It takes very little effort and doesn't require any technical knowledge.
Feb 17 '18 #3
gnawoncents
214 New Member
NeoPa,
Thank you for the warning. I read your linked article. Just to make sure I understand correctly--you're saying that the date format needs to be identified inside the command line? Would it be different depending on where one is in the world or only on how it is already stored in the database? I don't want to lead anyone astray and appreciate the insight!
Feb 18 '18 #4
NeoPa
32,557 Recognized Expert Moderator MVP
I'll try to explain as clearly and simply as I can.

Dates are stored the same way regardless. This is not about how they're stored. It's about how they're displayed. The problem is that people use the default display format in order to build up SQL strings (or commands) in their code.

If you say strX = datVar then the VBA interpreter will see a string on one side and a Date on the other and will know the Date needs to be converted to a string, so it works out which characters to include in this sub-string using what it knows about your locale settings. In the USA it will select a format that is actually validly recognised by SQL as exactly the date you're thinking of. In much of the rest of the world it would not.

A SQL command string is not designed for human viewing. That's an important point. It's not designed for human viewing. SQL is a command interpreter and it does so following clearly defined and specific rules. Just dumping some digits and other stuff that look to a human like it may be a date is absolutely not good enough. It must follow a standard format otherwise it's garbage.

You'll understand that exactly the same is going on when you say :
Expand|Select|Wrap|Line Numbers
  1. strX = "... WHERE ([DateField] Between #" & datVar & "# And Date())"
It sees a Date value that needs to be converted to a string. It uses your locale settings. Its only concern is to produce characters in order that represent a date string to the local human populace. There is nothing there to ensure it matches SQL date requirements. In most of the world it won't.

Consider one of the worst case scenarios. It's the first day of August and you're running the application in the United Kingdom instead of USA. Instead of :
Expand|Select|Wrap|Line Numbers
  1. ... WHERE ([DateField] Between #8/1/2018# And Date())
You get :
Expand|Select|Wrap|Line Numbers
  1. ... WHERE ([DateField] Between #1/8/2018# And Date())
Why is that a worst-case scenario? Because it doesn't fail! Users are likely to think all is well yet it's just used a completely different date from the one intended. Your business figures have just gown down the pan because someone sloppily referred to 8th January instead of 1st August.

With :
Expand|Select|Wrap|Line Numbers
  1. ... WHERE ([DateField] Between #2018-8-1# And Date())
That can never happen of course.
Feb 19 '18 #5
gnawoncents
214 New Member
NeoPa,
Thank you for the clarification. I will be more careful with dates and strings from here on out!
Feb 20 '18 #6
NeoPa
32,557 Recognized Expert Moderator MVP
Good for you :-)

It's not a problem that's obvious to most developers.
Feb 21 '18 #7
twinnyfo
3,653 Recognized Expert Moderator Specialist
NeoPa,

Very informative and useful! Not sure I'll be doing much outside the USA, but this helps me understand my world a bit better.

Thanks!
Feb 26 '18 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1665
by: nospamplease | last post by:
I'm new to MS Access and having a problem with making a report from an access database. I can't seem to expand the field in the report I called "notes" in the database. All the text is cut off...
4
1818
by: Clint Stowers | last post by:
Running Ak2 Daily there is a report that is run where a summation of the detail records is placed in the footer. Simple standard operation. What I would like to do at the time the report is...
3
1180
by: Bart Swisher | last post by:
I have a database I am building that is for a police department. On the report I need it to display the following information: Date of Incident, Offense discription, Narrative, Offender/s,...
3
4910
by: sara | last post by:
Hi - I have a button that runs 2 reports. If there is no data on the report, I use the No Data event, and tell the user, and Cancel the execution of that report. However, if the first report...
0
1630
by: KNN | last post by:
I have created a report in access 2003 using a query. Used some of the fields to display under page header. Used others to display under group headers and used the remaining under detailed...
1
1162
by: EgoSum | last post by:
Does anybody can explain in steps how can I load xml data in report and open it in reportViewer? There's a short xml example ProductSales.xml: <?xml version="1.0" standalone="yes"?>...
5
1390
by: JHNielson | last post by:
This seems like such a simple question, and I thought I knew how to do it, but I can't get it to work. I have a form that is bound to a table 'ETL" and users can enter data into that form. I want...
3
1583
by: keri | last post by:
Hi, I have recently being doing a lot of work in Excel so apologies if I refer to things in Excel terms. I need to create a report and cannot seem to get the data from my tables / queries in the...
3
5227
by: STEPHENSS | last post by:
Hi, I have a crystal report that has many subreports over many pages and Iam getting the following error Unable to save data with report, the save data is incomplete generate the saved data Yes...
2
1663
tuxalot
by: tuxalot | last post by:
I have an illustration of a human figure that will form the basis of a report showing injury information occurring in a work-force over time. I wish to pull injury date, body part injured and...
0
7260
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
7160
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
7384
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
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.