473,385 Members | 1,647 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,385 software developers and data experts.

Display results of query from a form in the same report each time the query is run

I have created a query which is run from a form. When the query is executed the results are displayed. I would like to have those results in a formatted report that can be printed if desired and not displayed on the screen. In addition once the formatted report has been created, I would like for the result for every query thereafter to be printed using the same formatted report. Now the hard part, would like to include the VBA in the coding that is assigned to the command button assigned to execute the query on the form, to produce the formatted report
May 24 '18 #1
14 2357
twinnyfo
3,653 Expert Mod 2GB
mcervenka1,

It may be that you are not fully aware of how queries and reports are related to each other.

A query simply gathers and presents data from your database, based on certain criteria. A report merely uses the results of the query.

So, if you have your query, you have the majority of your work done for this post. Simply create a report and set its record source to the query you have described. Add the fields from the qurey onto your report and format the report as desired. Once you save the report, any time you run the report, it will be based on the most current data pulled by the query. I hope this makees sense.

Your "hard part" is actually the easy part. Simply use DoCmd.OpenReport [ReportName], acNormal to run and print the report.

There may be slightly more to it, but that is the general idea.

We will be glad to guide you through any more challenging aspects of this....
May 24 '18 #2
makes sense. Please allow me try to clarify. I am running the query from a form. Entering the parameter information into the form and the push button to execute the query. Where would I add your coding? I am using macro's. Please see attachment containing: Form, Property Sheet, embedded macro commands, and query
Attached Files
File Type: docx Query Form Report.docx (136.1 KB, 220 views)
May 24 '18 #3
twinnyfo
3,653 Expert Mod 2GB
My first question would be, "Is it necessary to build your Query in the VBA?"

It is possible to create a query that uses the values from your Form. The Criteria in the query would be [Forms]![FormName]![TextBoxName].

It is possible to have the VBA create the Query Definition and then the Report can use that definition, but it is a bit more involved than what I have suggested.

Let us know the direction you want to go.

-------
Also, as a side note, I would recommend NOT using Macros, as they severely limit the capabilities of Access. Even the brightest experts on this forum are not usually very adept at using macros because of their inherent limitations. I do not believe you can do what you are suggesting by using macros (but I may be wrong). Stick to VBA and you have more control over all aspects of your project.
May 24 '18 #4
NeoPa
32,556 Expert Mod 16PB
Hi M.

It seems you really are opening an actual QueryDef in Datasheet View.

If I understand you correctly, instead of seeing the data in this format you'd prefer to see it embedded within a report which is properly designed to show the data in a more human-friendly way?

If that's the case then simply do as TwinnyFo says :
Design a report that uses that QueryDef (Often simply referred to as Query.) as its RecordSource. Then, when it comes to pressing the button on your Form, instead of opening the QueryDef you'd open the Report instead.

I have to say that I'd certainly agree with what Twinny says about avoiding the use of macros in Access, but I've said that before and ultimately it's your choice. To be fair, whichever approach you use should be fundamentally very straightforward.
May 25 '18 #5
NeoPa. I found "Convert Form's Macro to VBA" in Access. Is this a good tool to use to convert my form?
May 29 '18 #6
twinnyfo
3,653 Expert Mod 2GB
mcervenka1,

Yes, that is a good place to start converting your macros to VBA. In nearly all cases, the form will continue to work as previously, but the macros will be removed. I have heard of some instances in which the form does not work as expected because of the conversion process--however, I have not experienced that and don't expect that you should have many problems, based on your descriptions so far.

let us know how things come out and we can continue to work from there!
May 29 '18 #7
Neopa and twinnyfo...the conversion ran like a charm,, EXCEPT when I enter the values (start date and end date) for the query in my form and then a parameter value pop up box ask to enter the same values (start date and end date), then the report will display. I think I know why, when reading the VBS for the form, I see where the DoCmd is executing the query causing the parameter value popup box because there is no coding for Filter that would allow a search on the values entered on the form. Am I close??? I am basing my guestimation on the coding in the Record update VBA we discussed on the posting for displaying only single records or all it's doubles and not the rest of the records in the query. Other wise, if I didn't convert to VBA the form would allow me to enter the value and the query would execute and shows the results on the screen.
Attached Files
File Type: docx Macro Conversion.docx (77.0 KB, 144 views)
May 29 '18 #8
twinnyfo
3,653 Expert Mod 2GB
mcervenka1,

First (again) - Please do not cut and paste screenshots of your code. Simply cut and paste the code itself.

Second, there is nothing in the code you provided that would indicate why there is a pop up requesting the values in the text boxes. However, my guestimation is that when you converted to VBA, it "may" have created a new form? Thus, the query you are calling (Exams Surrender Query), is searching for values on a form that is not currently open.

This is a hunch, but a probable one. Let us know what you find.
May 29 '18 #9
PhilOfWalton
1,430 Expert 1GB
Sorry to butt in, but I think you are missing the point.

The VBA should be opening the report, NOT the Query

There should be a query as the recordsource for the report that includes criteria that refer to the Forms!FormName!StartDate and Forms!FormName!EndDate.

Don't forget that both these dates will need a hash (#) on either side of those date fields

Phil
May 30 '18 #10
twinnyfo
3,653 Expert Mod 2GB
True, Phil,

I was focused on getting the Query/Form discrepancy fixed first. Hopefully, the query will produce the results we want. Then when the query is assigned to the Report (which hopefully it already is), we call the report from the Form.
May 30 '18 #11
twinnyfo . you were right. I copied the form and made used the marco VBA converter on the copy. I copied to test the changes on the copy and if it worked, I would make changes on the original form. When I did use the converter on the original form, it worked perfectly and did not show the parameter value popup box.
May 30 '18 #12
twinnyfo
3,653 Expert Mod 2GB
And, so now back to Phil's observation. You should call the report, not the query from your Form. As long s that Query is assigned to the Report's Record Source, all should be fine.
May 30 '18 #13
NeoPa
32,556 Expert Mod 16PB
PhilOfWalton:
Don't forget that both these dates will need a hash (#) on either side of those date fields
That is absolutely not as simple as that. Only American date formats (and those that use a similar one) can reliably work simply by adding hashes (#) as delimiters, and they aren't portable. There are multiple valid date formats for SQL, but English, and any European, formats cannot safely be used. Please see Literal DateTimes and Their Delimiters (#) for a full explanation.
May 31 '18 #14
NeoPa
32,556 Expert Mod 16PB
MCervenka:
NeoPa. I found "Convert Form's Macro to VBA" in Access. Is this a good tool to use to convert my form?
As far as tools go it'll do the job. However, do bear in mind that such code will always be very clumsy. It's also very limited. You get only what a macro can give you, which limitation is one of the reasons not to use them if you can avoid them. That said, as a first step it's not a bad approach.

Where possible though, learn some of the basics from them and then move on as quickly as you can. You're far better off creating your logic in VBA to start with. Many of the macro conversions use RunCommand() which should be avoided wherever there's an alternative - and there usually is.
May 31 '18 #15

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

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
6
by: B Love | last post by:
I am wondering if I can have a dynamically generated report based upon the results of a query (in Access2000). Any ideas? Related to that (if that cannot be done) can the output of a query...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
13
by: lightning | last post by:
I have a search form that returns records to another form, rather than a table. Here are my questions: 1) Is it possible to export the form results (as opposed to query results) to CSV? I've been...
13
ChaseCox
by: ChaseCox | last post by:
Hello Everyone, I am wanting to count the occurence of different records, for example: MOT484354 PRN487522 COM45757 COM45775 PRN124872 PRN127754
3
WyvsEyeView
by: WyvsEyeView | last post by:
This seems like it should be so easy to do. I have a table, called tblTopics. Each topic can have one or more instances, contained in a table called tblTopicInst. tblTopics is bound to a form called...
3
by: vljones | last post by:
I have a report with sub reports. The sub reports are query based. The queries perform a Count. Where no data exists in the table, no results are provided. Is there a way to populate the sub...
3
by: Pierkes | last post by:
Hi, I have a report which uses a query to generate the records. The query base is a table called . In the table are 10 fields registering the whishes of the client called through that all use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.