473,837 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems w/ ADODB.Recordset as Report Source...

Oko
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 have created an
ADODB.Recordset in the reports OPEN event, built the necessary records
inside of it, and then bound the report to this newly created
recordset.

Here's the rub:

It seems that no matter what, it iterates through all of the records
but each record displays the value of the last record. So assuming one
field named rptName (which is my setup) where there are 4 records that
say "Oscar", "Dennis", "John", and "Terrance" respectively the report
would return:

Terrance
Terrance
Terrance
Terrance

Obviously this is sub-optimal.

Anyone have any idea what I'm missing and how I can resolve this?

TIA

-j
Nov 27 '07 #1
6 5179
The problem is that you are using an Access ADP and still trying to
develop in terms of Access. When using an ADP you aren't really in
Access anymore. You are now in Sql Server country but can still use
VBA. The ADP is only a Front End to Sql Server. You need to think in
terms of stored procedures and Transact Sql.

For your report from the ADP you need to create your recordsource from a
stored procedure. First, create your stored procedure. Run it in Query
Analyzer and see if the resultset is what you want. If yes, then set
the StoreProc as the recordsource for your report object in the Access
ADP.

At the bottom of the property sheet for the ADP Report object is a
textfield for Input Parameters. You can populate this textfield like
this with default parameters:

@UserId='tiger' , @Begindate='12/15/07', @EndDate='12/31/07'

And these would be parameters in your stored procedure.

Recordset Objects won't work in an ADP. The sql Server equivalent of a
Recordset object is a Cursor. Cursors are used primarily as an add-hoc
tool in Query Analyzer to examine data SLOWLY. Cursors are slow and
resource intensive.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 27 '07 #2
Oko
Which bares "the rub": The Admins will not allow us to create the
additional Stored Procs - forcing us to utilize this particular type
of solution. Would love to go another direction - but can't [at least
not yet] and I need results within a reasonable time frame.

Playing with a .movefirst and a .movelast during this last so many
minutes has allowed me to control whether the first record or last
record is the record displayed. This - to me - indicates that the
report is not properly moving through the recordset on its own.

Any ideas on how I might be able to properly control that movement
would be appreciated.

Rich P wrote:
The problem is that you are using an Access ADP and still trying to
develop in terms of Access. When using an ADP you aren't really in
Access anymore. You are now in Sql Server country but can still use
VBA. The ADP is only a Front End to Sql Server. You need to think in
terms of stored procedures and Transact Sql.

For your report from the ADP you need to create your recordsource from a
stored procedure. First, create your stored procedure. Run it in Query
Analyzer and see if the resultset is what you want. If yes, then set
the StoreProc as the recordsource for your report object in the Access
ADP.

At the bottom of the property sheet for the ADP Report object is a
textfield for Input Parameters. You can populate this textfield like
this with default parameters:

@UserId='tiger' , @Begindate='12/15/07', @EndDate='12/31/07'

And these would be parameters in your stored procedure.

Recordset Objects won't work in an ADP. The sql Server equivalent of a
Recordset object is a Cursor. Cursors are used primarily as an add-hoc
tool in Query Analyzer to examine data SLOWLY. Cursors are slow and
resource intensive.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 27 '07 #3
If you don't have development rights on the sql server then I would
scrap the ADP solution and use an mdb and ADO to work with the data from
the sql server. Then you can start thinking in Access terms again.

If your employer is bent on the ADP without the flexibility to develop
required procedures on the sql server then your only other option would
be to start playing solitaire.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 27 '07 #4
Oko
This IS possible. The problem can be solved using the FormatCount
parameter in the report's Detail_Format() event, combined with a value
stored somewhere to say if you're on the first record or not. When
FormatCount = 1 you should advance the ADODB.Recordset via code
(unless you're on the first record). This will force the report to
iterate through your recordset - giving you the results you need.

To be complete:

The ADODB.Recordset is first created in the Report_Open() event as a
New ADODB.Recordset . This is a temporary recordset residing in local
memory - and not on the SQL Server. The code for the structure is:

Dim rstAttachments As ADODB.Recordset

Set rstAttachments = New ADODB.Recordset
With rstAttachments
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Fields.Append "rptName", adVarChar, 255
.Fields.Append "delete", adBoolean
.Fields.Append "recNo", adInteger
.Fields.Refresh
.Open
End With

The recordset is then populated - in this case using information in a
series of checkboxes in a user form - and then once populated is
assigned to the report's Recordset property. The original recordset -
rstAttachments - is then set to NOTHING, and the report's recordset is
moved to the first record (just to be safe).

Set Me.Recordset = rstAttachments
Set rstAttachments = Nothing

Me.Recordset.Mo veFirst

In the ReportHeader_Fo rmat() Event the Reports Tag Property is set to
0. This allows me to know when I'm in the Detail_Format() event if I'm
viewing the very first record or not. This is important because I
don't want to advance the cursor if I'm on the first record - only for
the later records do I want to advance it.

Me.Tag = 0

The final bit is in Detail_Format() . Taking my cue from the value of
FormatCount, I move the record pointer ahead one when FormatCount = 1
- EXCEPT when Me.Tag = 0. When Me.Tag = 0 I ignore the record pointer
and set Me.Tag to 1 so that the next time FormatCount = 1 the routine
will work.

If FormatCount = 1 Then
Select Case Me.Tag
Case 0
Me.Tag = 1
Case Else
With Me.Recordset
.Fields("delete ") = True
.MoveFirst
.Find ("delete = False")
End With
End Select
End If

Note that in the above routine I used a slightly paranoid approach. I
marked records off as they were formatted and then traveled back to
the first record and searched for the first, unformatted record. I
have no reason to believe a simple .movenext is insufficient - I'm
just paranoid like that. Also, this may not be the best way to go for
a large recordset.

On a final note, I simply close the recordset once I'm done with it
via the Report_Close() event.

With Me.Recordset
.Close
End With

Oko wrote:
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 have created an
ADODB.Recordset in the reports OPEN event, built the necessary records
inside of it, and then bound the report to this newly created
recordset.

Here's the rub:

It seems that no matter what, it iterates through all of the records
but each record displays the value of the last record. So assuming one
field named rptName (which is my setup) where there are 4 records that
say "Oscar", "Dennis", "John", and "Terrance" respectively the report
would return:

Terrance
Terrance
Terrance
Terrance

Obviously this is sub-optimal.

Anyone have any idea what I'm missing and how I can resolve this?

TIA

-j
Nov 28 '07 #5
On Nov 27, 5:21 pm, Oko <without...@gma il.comwrote:
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 have created an
ADODB.Recordset in the reports OPEN event, built the necessary records
inside of it, and then bound the report to this newly created
recordset.

Here's the rub:

It seems that no matter what, it iterates through all of the records
but each record displays the value of the last record. So assuming one
field named rptName (which is my setup) where there are 4 records that
say "Oscar", "Dennis", "John", and "Terrance" respectively the report
would return:

Terrance
Terrance
Terrance
Terrance

Obviously this is sub-optimal.

Anyone have any idea what I'm missing and how I can resolve this?

TIA

-j
My idea is that you did something wrong. If you post your code I, or
someone else, might even be able to tell you what it is. If we can't,
we will have learned something new from your code. If you don't post
your code, I'll just write you off as the kind of inexperienced newbie
who might accept the rest of the erronoeous and misleading replies you
have received, as valid.
" When using an ADP you aren't really in Access anymore". There's
stupid and then there's this guy who says whatever come into his head;
usually it's wrong!
Nov 28 '07 #6
On Nov 27, 8:30 pm, Oko <without...@gma il.comwrote:
This IS possible. The problem can be solved using the FormatCount
parameter in the report's Detail_Format() event, combined with a value
stored somewhere to say if you're on the first record or not. When
FormatCount = 1 you should advance the ADODB.Recordset via code
(unless you're on the first record). This will force the report to
iterate through your recordset - giving you the results you need.

To be complete:

The ADODB.Recordset is first created in the Report_Open() event as a
New ADODB.Recordset . This is a temporary recordset residing in local
memory - and not on the SQL Server. The code for the structure is:

Dim rstAttachments As ADODB.Recordset

Set rstAttachments = New ADODB.Recordset
With rstAttachments
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Fields.Append "rptName", adVarChar, 255
.Fields.Append "delete", adBoolean
.Fields.Append "recNo", adInteger
.Fields.Refresh
.Open
End With

The recordset is then populated - in this case using information in a
series of checkboxes in a user form - and then once populated is
assigned to the report's Recordset property. The original recordset -
rstAttachments - is then set to NOTHING, and the report's recordset is
moved to the first record (just to be safe).

Set Me.Recordset = rstAttachments
Set rstAttachments = Nothing

Me.Recordset.Mo veFirst

In the ReportHeader_Fo rmat() Event the Reports Tag Property is set to
0. This allows me to know when I'm in the Detail_Format() event if I'm
viewing the very first record or not. This is important because I
don't want to advance the cursor if I'm on the first record - only for
the later records do I want to advance it.

Me.Tag = 0

The final bit is in Detail_Format() . Taking my cue from the value of
FormatCount, I move the record pointer ahead one when FormatCount = 1
- EXCEPT when Me.Tag = 0. When Me.Tag = 0 I ignore the record pointer
and set Me.Tag to 1 so that the next time FormatCount = 1 the routine
will work.

If FormatCount = 1 Then
Select Case Me.Tag
Case 0
Me.Tag = 1
Case Else
With Me.Recordset
.Fields("delete ") = True
.MoveFirst
.Find ("delete = False")
End With
End Select
End If

Note that in the above routine I used a slightly paranoid approach. I
marked records off as they were formatted and then traveled back to
the first record and searched for the first, unformatted record. I
have no reason to believe a simple .movenext is insufficient - I'm
just paranoid like that. Also, this may not be the best way to go for
a large recordset.

On a final note, I simply close the recordset once I'm done with it
via the Report_Close() event.

With Me.Recordset
.Close
End With

Oko wrote:
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 have created an
ADODB.Recordset in the reports OPEN event, built the necessary records
inside of it, and then bound the report to this newly created
recordset.
Here's the rub:
It seems that no matter what, it iterates through all of the records
but each record displays the value of the last record. So assuming one
field named rptName (which is my setup) where there are 4 records that
say "Oscar", "Dennis", "John", and "Terrance" respectively the report
would return:
Terrance
Terrance
Terrance
Terrance
Obviously this is sub-optimal.
Anyone have any idea what I'm missing and how I can resolve this?
TIA
-j
I just tried this in Access 2002. It works. Perhaps, there is
something here that will help.

Private Sub Report_Open(Can cel As Integer)
Dim r As ADODB.Recordset
Set r = New ADODB.Recordset
Dim z As Long
With r
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOpti mistic
.Fields.Append "AccountID" , adInteger
.Fields.Append "CommonName ", adLongVarChar, 255, adFldIsNullable
.Fields.Append "Valid", adBoolean
.Open
For z = 1 To 3
.AddNew Array(0, 1, 2), Array(z, Chr$(z + 64), CBool(z Mod 2))
Next z
.UpdateBatch
.MoveFirst
End With
Set Me.Recordset = r
End Sub

It shows

1 A check
2 B
3 C check
Nov 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2882
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a disconnected ADODB.Recordset from System.Data.DataTable data. Below is the source code I am implementing to test the process. I do not get any error, that I can see. The problem I have is that at the end, the recordset seems to be empty. Any...
5
29858
by: Simone | last post by:
Hello I hope you guys can help me. I am very new to ADO... I am creating a ADODB connection in a module and trying to access it from a command button in a form. Function fxEIDAssgn(plngEID As Long) As Boolean Dim rsAssignedUser As ADODB.Recordset Dim strSelectUser As String
0
2691
by: CFW | last post by:
I thought this was going to be easy but I'm missing something . . . I need to open an ADODB recordset using the recordset source for a list box on my for. When my form opens, the list box ADODB recordset is established and set during On Open. Next I want to populate a recordset from that list box so I can filter it on a single field using the value of a combo box for the filter string. I have a second combo box that i woul like to use...
3
6633
by: | last post by:
Hello ppl, I have snippet that works fine udner ADODB with VB6, but something wrong with it in Vb.NET. Anyone can help? Recordset1 (ADODB.Recordset) Error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. Error Source: SELECT * FROM Accounts
0
1876
by: sonasiva | last post by:
hai Iam creating website using ASP i wnts my clients to register first to vist site using username and password,,this i need to do iam getting error like this ADODB.Recordset (0x800A0BB9) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. in line objRS.Open mySQL, objConn,adOpenKeyset, adLockPessimistic, adCmdText
0
1553
by: PCroser | last post by:
I have encountered a problem when querying a table. The query passed data into a recordset which should have resulted in many records but has returned EOF. After debugging the code the only solution i have found is that i have set the recordset to NEW ADODB.RECORDSET two times before actually perfoming the rs.open (once in the main program and once in the dll which contains the loadrecords function). MAIN PROGRAM Dim rs as NEW...
1
2031
by: sanika1507 | last post by:
Hi .Actually I want to count the number of records in a recordset. So I m using the ADODB.Recordset. I just want some one to correct me. Set Cmd = Server.CreateObject("ADODB.Recordset") Cmd.ActiveConnection = C Cmd.CommandText = "CP.dbo.spBCode" Cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("@Bcode", adVarChar, adParamInput, 255, dbQuoteOrNull(sBCode))
1
3376
by: shivasusan | last post by:
Hi Friends! Please Help me! How i can solve this error? Please explain me, what is the error and how to solve? Error Type: ADODB.Recordset (0x800A0E7D) The connection cannot be used to perform this operation. It is either closed or invalid in this context. /H3finalresult/include/accept_reject2.asp, line 18
1
4339
by: Kloj | last post by:
I have two queries in MS.Access, qry1 and qry2. qry1 is based on table1, qry1 has two fields i.e Qty and Product. qry2 is sum of qry1. qry2 has two fields i.e Sum_of_Qty and Product, qry2 is Grouped on Product. The problem is following,
0
9843
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9682
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10877
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10626
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10273
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9402
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4474
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 we have to send another system
2
4041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.