473,395 Members | 1,742 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.

Recordset Report Problems

52
I've googled this and I've come up with nothing.

I'm using the code below to produce a recordset for a report. all seems to work just fine except when i try to print I get the error:

"A custom macro in this report has failed to run, and is preventing the report from rendering"

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Dim rsOne As Recordset
  5.  
  6. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  7.  
  8.     Me.txtFullName.Value = rsOne("FirstName") & " " & rsOne("LastName")
  9.  
  10.     rsOne.MoveNext
  11.  
  12. End Sub
  13.  
  14. Private Sub Report_Open(Cancel As Integer)
  15.  
  16.     Dim SQL As String
  17.  
  18.     SQL = "SELECT * FROM ReminderFinal"
  19.  
  20.     Set rsOne = CurrentDb.OpenRecordset(SQL)
  21.  
  22.     rsOne.MoveFirst
  23.  
  24. End Sub
  25.  
I've traced the problem to .MoveNext in the Sub Detail_Format, but when I comment it out my report no longer steps through all of the records in the record set.

I'm new to using VBA for reports so (again) I'm happy to believe that I am not understanding some kind of fundamental logic for Recordsets and reports.

Using Access2007, XpOS.
Mar 26 '09 #1
9 3022
ChipR
1,287 Expert 1GB
Is your report itself based on ReminderFinal? If not, base it on a query that includes the name information, rather than using that code.

Then, in the txtFullName control on the report in design view put:
=[FirstName] & " " & [LastName]
Mar 26 '09 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi Chinde. The custom recordset you are opening is nothing to do with the report. It is not the same recordset as the report itself is opening, which is defined by the recordsource of the report itself.

As the report is based on a specific recordsource, and you are trying to fill values of controls with values drawn from an unrelated recordset, you may be trying to set a value for a bound control - one that is bound to a field in the underlying recordset. This is certain to fail.

To set up custom names and so on it is far better to include these as calculated fields within the underlying query used as the recordsource of your report. If you do this you will have no need for custom coding the way you are doing.

If, for some reason, you don't want to include the custom fields in your underlying query you can set an unbound textbox to be firstname concatenated with lastname, but you'd have to place the two named fields onto your report and then set their visible properties to false to hide them first.

My feeling is that your current approach is not going to lead you anywhere except to frustration, as there is no chance that a recordset opened from within a report will have any bearing on what your report is really working on - these are completely different things.

If you could tell us what you are trying to achieve I'm sure we could advise you how to do it without coding at all if possible...

-Stewart

ps apologies to Chip for cross-posting - didn't see yours when I was preparing mine.
Mar 26 '09 #3
Chinde
52
ChipR
It is based on the entire contents of the table ReminderFinal, the method you outlined is more or less the method I wished to avoid, as I really wanted to manipulate the data dynamically via the VBA. I guess that I'm just not as comfortable with the expression builder syntax. I also wanted to pull other bits of info in from other related tables.
Mar 26 '09 #4
ChipR
1,287 Expert 1GB
You can set the value of a control to a function, if that makes it any easier, but I would base the report on a query that has all the data you need in it.

Expand|Select|Wrap|Line Numbers
  1. =GetFullName([FirstName],[LastName])
  2.  
  3.  
  4. Function GetFullName (FirstName As String, LastName As String) As String
  5.    GetFullName = FirstName & " " & LastName
  6. End Function
Will do the same thing, but you can see that your function could be as complicated as you like.
Mar 26 '09 #5
Chinde
52
Thanks both.

I will follow what both of you have advised and return to the more straight forwards method using the reports native recordsource. Though I am sure I will come to a dead end with my knowledge in that direction.

I'll be back.
Mar 26 '09 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi Chinde. I'm still not sure what you would hope to gain by code-based manipulation - but when you mention taking data from other tables this really is much, much easier to do by joining the tables into the query on which the report is based. It is also much easier for others to maintain - code-based solutions can be hard for others to understand, never mind to maintain, whereas queries are much more straightforward.

An informal rule in using Access is to avoid trying to develop bespoke coding for things which can be done using native Access features with little effort. You will not replicate the product's overall ease of use, years of development and general efficiency at doing what it does if you go that route.

I use minimal bespoke coding in reports to do things which cannot be easily achieved in other ways - for example bespoke formatting of particular fields (emboldening, changing font characteristics, and so on), or setting particular values visible dynamically.

In many years of report development in Access I have never had any occasion to use an internal recordset variable or to loop through any records other than those the report was already working on. All the main 'work' in my reports is contained in the (sometimes complex) underlying queries used as the report's recordsource - not in the report itself.

I strongly advise using the facilities already there instead of trying to replicate them through difficult-to-verify code - doing so is not a good use of your time nor that of any developer who takes over such a database from you. I know that you have said you will now go this route, but it clearly is with somewhat of a heavy heart. It really is the best way to go!

-Stewart
Mar 26 '09 #7
Chinde
52
Thank you, I do appreciate the advice from a seasoned professional.

Like I said I'm just not as comfortable with the expression builder as I am with code based solutions, but I will persevere with the new set of syntax.

On a slightly different tack I could set up code based solutions as functions and use them in the expression builder and hence the report?? Or again is this the road to frustration??

Though I am pre-empting problems which I don't know will come.
Mar 27 '09 #8
Stewart Ross
2,545 Expert Mod 2GB
Hi Chinde. Where no existing function can fit your needs it is indeed quite normal to write a bespoke VBA function and use it to provide data in calculated fields of a query.

The only downside is that the use of bespoke function calls in a query limits the generality of the SQL if it might be used or transferred out of the Access environment where you do not have the equivalent VBA functionality available.

E.g. if you connect to such a query using an ODBC driver from Excel the MS Query object which runs the SQL will not recognise any bespoke function calls.

Not a problem if you stay within Access, however.

-Stewart
Mar 27 '09 #9
Chinde
52
Thank you. progress is happening and so far so good.
Mar 27 '09 #10

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

Similar topics

0
by: Kevin R | last post by:
Question: I have a situation where I would like to prepare a Recordset object within Visual Basic (6.0), and then use the MS Access COM API's to Show a report built off of the data in my...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
1
by: Robert Davis | last post by:
I would like to be able to create a recordset in MS Access 2000 that allows a macro to run and create a report for each ID that appears in the recordset. So I thought that I would use a scheduling...
8
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I...
1
by: Zlatko Matić | last post by:
Hello. I have a MS Access front end/PostgreSQL back-end combination. There is a report with nested graph (linked master/child fields). I used saved pass-through queries for both Record Source of...
2
by: JonC | last post by:
I have a database where the user selects recordsets via a form with 2 levels of nested subforms. The recordsets are filtered using a series of linked combo boxes and I would like to be able to...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
10
by: nspader | last post by:
I want to start out saying I am a novice code writer. I am trying to send a report via email based on each supplier. The code below is what I am using. I need to base recordset on Form, report...
3
by: Gord | last post by:
Me again, I'm new to Access and am self teaching from a couple of books, so bear with me. (I've got a little experience with Visual Basic) As I understand so far, if I want to perform a bunch...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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...
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...
0
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,...

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.