Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2005, 02:34 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Report based on query programatically

Hey all - I want to generate a report programmatically based on an existing query, or alternatively on an SQL statement. The query is a little complex (this is copied from the Query's SQL view):
SELECT TESTS.facilityID, TESTS.testDate, TESTS.testTypeID, DateAdd("m",[testPeriod],[testDate]) AS DateDue
FROM FACILITIES INNER JOIN (TESTTYPES INNER JOIN TESTS ON TESTTYPES.testTypeID = TESTS.testTypeID) ON FACILITIES.facilityID = TESTS.facilityID
WHERE (((DateAdd("m",[testPeriod],[testDate])) Between Date() And DateAdd("m",3,Date())));

which is why I thought it would be easier to use the existing query.
So, how do I get the record source of the report to be the records returned by this query? ALternatively, how can I code this complex SQL statement into VBA?
Thank you


 
Old March 20th, 2005, 06:11 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SQL in VBA is string format. Assign a variable and just copy it into "" and then aply it to a control property RecordSource.
A few tricks you need to know.
If the line is too long:
..." _
& "...;"
You must identify the value string for instance in the WHERE statmnt:
"...WHERE ((table.field)= '" & yrStrValue & "');"
"...WHERE ((table.field)= #" & yrDateValue & "#);"
"...WHERE ((table.field)= " & yrValue & ");"
*note the number of ().
In your line would be Between #" & yrDate & "# And ...
Please ask if you need more

 
Old March 22nd, 2005, 08:57 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you josemariagomes - I think it is working now. Another trick I needed to know was to use "" two double quotes inside the SQL string in VBA where I had " one double quote before as in:
SELECT TESTS.facilityID, TESTS.testDate, TESTS.testTypeID, DateAdd
WHERE (((DateAdd(""m"",[testPeriod],[testDate])) Between Date() And DateAdd(""m"",3,Date())));
Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Programatically Rendering a Report mdonnel ASP.NET 3.5 Basics 0 December 3rd, 2008 05:19 PM
Export Crystal Report Programatically Harinder.Dhamija ASP.NET 2.0 Basics 0 July 20th, 2007 08:28 AM
Form Input, Parameters, Report Based on Query DavidWE Access VBA 2 November 6th, 2006 10:36 AM
subform based on a query Vince_421 Access VBA 2 May 10th, 2006 04:38 AM
Graph Based Query maha Access 0 October 2nd, 2003 03:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.