![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
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 *** |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
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 |
#7
| |||
| |||
|
|
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.MoveFirst In the ReportHeader_Format() 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |