473,395 Members | 2,689 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,395 software developers and data experts.

Associating Report field to VB code - where 2 find good reference

Hi,
I am fairly new to Access programming and Reports. I have inherited a project and am trying to understand some of the inner workings. There is a field named Overall in the Detail section of my report. The Control source for this field is SumOfbalance (and no - I did NOT forget to capitalize the b in balance). After a good deal of digging, I managed to find a reference to this field in a query in the VB code associated with this report. A stub of the VB code is shown below.

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Err_Report_Open

Dim strSQL As String
Dim strInnerSQL As String
Dim strFROM As String
Dim strWHERE As String
Dim strGROUPBY As String
Dim strORDERBY As String

'-- Create SQL for report record source


strORDERBY = " ORDER BY [AcctNumber] & [idsuffix]"

strSQL = "SELECT DISTINCT tblAccount.Accttyp, [AcctNumber]" & _
" & [idsuffix] AS ACCT_REC, tblAccount.primname," & _
" tblAccount.street1, tblAccount.street2, tblAccount.city," & _
" tblAccount.state, tblAccount.zip," & _
" IIf(IsNull(Sum(qryAcctRec.balance)),0,Sum(qryAcctR ec.balance))" & _
" AS SumOfbalance"
strFROM = " FROM tblAccount LEFT JOIN qryAcctRec ON" & _
" tblAccount.pkeyAccount = qryAcctRec.fkeyAccount"
strGROUPBY = " GROUP BY tblAccount.Accttyp," & _
" [AcctNumber] & [idsuffix], tblAccount.primname," & _
" tblAccount.street1, tblAccount.street2," & _
" tblAccount.city, tblAccount.state, tblAccount.zip" & _
" HAVING (((tblAccount.Accttyp) = 'EC'))"
Me.RecordSource = strSQL & strFROM & strGROUPBY & strORDERBY

'-- Print the report creation date on each page
Me.lblPrintedOn.Caption = "Created " & Now()

Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox Err.Description
Resume Exit_Report_Open
End Sub


I sort of understand how it works, but am a bit perplexed as to how someone would ever figure this out since I have yet to find any documentation that explains this way of implementing a report - essentially associating a report field with a variable that is defined in an AS clause of a query in the report's Visual Basic code.

I appreciate any information on where I might find additional information on advanced reporting topics like this.

Thanks....
Oct 25 '07 #1
2 2018
I'm far from an expert. However, I do recognize that this code is merely creating a query programmatically your field in question is calculated. So it is similar to
everything you would do when you build a query.

expr1: [variable1]+[variable2]

trouble: [dogs]+[cats] ; )

In agreement, I have no idea why the query is coded except that it probably relates to a form used to create a report. It probably makes the form more modular, flexible. the IIf statement is just ensuring you don't get an #error if in my silly formula there were no dogs and the field is null. All this you probably know.
Oct 26 '07 #2
Jim Doherty
897 Expert 512MB
Hi,
I am fairly new to Access programming and Reports. I have inherited a project and am trying to understand some of the inner workings. There is a field named Overall in the Detail section of my report. The Control source for this field is SumOfbalance (and no - I did NOT forget to capitalize the b in balance). After a good deal of digging, I managed to find a reference to this field in a query in the VB code associated with this report. A stub of the VB code is shown below.

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Err_Report_Open

Dim strSQL As String
Dim strInnerSQL As String
Dim strFROM As String
Dim strWHERE As String
Dim strGROUPBY As String
Dim strORDERBY As String

'-- Create SQL for report record source


strORDERBY = " ORDER BY [AcctNumber] & [idsuffix]"

strSQL = "SELECT DISTINCT tblAccount.Accttyp, [AcctNumber]" & _
" & [idsuffix] AS ACCT_REC, tblAccount.primname," & _
" tblAccount.street1, tblAccount.street2, tblAccount.city," & _
" tblAccount.state, tblAccount.zip," & _
" IIf(IsNull(Sum(qryAcctRec.balance)),0,Sum(qryAcctR ec.balance))" & _
" AS SumOfbalance"
strFROM = " FROM tblAccount LEFT JOIN qryAcctRec ON" & _
" tblAccount.pkeyAccount = qryAcctRec.fkeyAccount"
strGROUPBY = " GROUP BY tblAccount.Accttyp," & _
" [AcctNumber] & [idsuffix], tblAccount.primname," & _
" tblAccount.street1, tblAccount.street2," & _
" tblAccount.city, tblAccount.state, tblAccount.zip" & _
" HAVING (((tblAccount.Accttyp) = 'EC'))"
Me.RecordSource = strSQL & strFROM & strGROUPBY & strORDERBY

'-- Print the report creation date on each page
Me.lblPrintedOn.Caption = "Created " & Now()

Exit_Report_Open:
Exit Sub

Err_Report_Open:
MsgBox Err.Description
Resume Exit_Report_Open
End Sub

I sort of understand how it works, but am a bit perplexed as to how someone would ever figure this out since I have yet to find any documentation that explains this way of implementing a report - essentially associating a report field with a variable that is defined in an AS clause of a query in the report's Visual Basic code.

I appreciate any information on where I might find additional information on advanced reporting topics like this.

Thanks....
Looking at the post there is nothing specifically unorthodox about the authors implementation of that reporting technique. As has been already mentioned the reports recordsource is merely being built on the fly when the report runs and the SQL syntax supports the reports fielded output.

The syntax is no different to that which consitutes a saved query in Access except that it is being used in code. It would seem to me the author has decided to take the view that the SQL, given that it is fixed and specific to the report, might be best saved with the structure of the report itself rather than as saved SQL (in favour of this decision) over time this could have, in the absence of that decision added potentially to a very long list of queries which would have to be scrolled through in the query window (reasoning based on the projected life cycle of the software?). Alternatively the designer might have built 50 reports all the same as that one.... the only marked difference being 50 hard coded HAVING clauses.

A pat on the back for perception of system object overload some might say in the early days of design and a smack on the wrist from those who asked that same designer for 49 extra reports once every two weeks for the last two years having stipulated originally that they definitely only needed one or two maybe three at the most and now..... because they didnt think far enough ahead, the designer must ....in the best interest of the organisation you understand....get it in the neck. LOL

Some others might also take the view that any SQL is best saved for performance reasons as a saved query in a centralised area so that it can be easily referenced.

The long and short of this is this, the technique employed is nothing uncommon yes it is advanced Access and 'will' easily be recognised by individuals with the relevant skillset. The documentation, disciplines and adherence to business rules employed in the design concept naming convention as with anything else is another matter entirely. as I am sure you appreciate and which I sense maybe where your perplexion lies?

As for readable material I have a huge stack of 4" thick manuals here ready for the next car boot sale if your interested? :))))

Regards

Jim :))
Oct 26 '07 #3

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

Similar topics

4
by: DerekM | last post by:
I have a database project that I created with several forms and reports. I would like to be able to declare a single title and be able to change the title on all the forms and reports by changing...
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...
3
by: MT 2MB | last post by:
I created an access journal entry program many years ago. It works for all and was working for an individual until recently. The report shows ?Name! for every instance it repeats in the report. ...
4
by: Mal | last post by:
I have an ACC 2000 database that has a strange behaviour I have a small table, with just a few fields... My report has very simple grouping and sorting, no code bar a NODATA event. I have a...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
8
by: David Horsman | last post by:
I have a report that lists File-B. My macro runs this report using a query as a filter. The query uses two files, the parent File-B and with a 0-many relationship to File-C. The query selects...
0
by: z.ghulam | last post by:
Hi, I'm creating a new databse and have a couple of problems I'd greatly appreciate any feedback on. 1) I have an order form and would like to set it, so that when the form is opened, the focus...
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
3
by: egarobar | last post by:
I am using Access 2003 (on WinXP) to read from an Oracle db, where there is a table with a CLOB which is a variable-size text field. In the 'linked table' which is created in the Tables panel of...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.