473,394 Members | 1,840 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,394 software developers and data experts.

Access Reports from a SQL BackEnd

8
OK, I'll tell you what i've got so far. On opening an Access Report I am running a Stored Procedure (a Select Query). Now my Recordset fields have values, but I cannot associate them to the controls I have placed on my Report. What am I doing wrong?? For example

txtFamilyName=rs.Fields(2)

Produces a runtime error 438. Object doesn't support this property or Method. I've tried assigning a String Variable to the field 1st, and then assign the variable to the control, but I get the same error.

Please Help!!! Getting pretty desperate.
Jan 4 '07 #1
8 4920
NeoPa
32,556 Expert Mod 16PB
You are sort of doing it back-to-front.
You need to define and test a recordset (table/query linked query) that produces the fields you expect (If linked to stored procedure check the datatypes of the returned values match what you require).
Next you need to bind the report to this recordset (Not a RecordSet in the code but an Object that returns a recordset (table/query as specified earlier). Put it's name in the reports Record Source property.
Now, the controls on the report that can take field values, can themselves be bound, by entering the name of the relevant field in the controls 'Control Source' property.
HTH.
Jan 4 '07 #2
feets
8
You are sort of doing it back-to-front.
You need to define and test a recordset (table/query linked query) that produces the fields you expect (If linked to stored procedure check the datatypes of the returned values match what you require).
Next you need to bind the report to this recordset (Not a RecordSet in the code but an Object that returns a recordset (table/query as specified earlier). Put it's name in the reports Record Source property.
Now, the controls on the report that can take field values, can themselves be bound, by entering the name of the relevant field in the controls 'Control Source' property.
HTH.
Thanks for getting back to me. I have to admit I'm a bit of a novice to vb, so I'm a bit confused how to bind the report to the recordset. I don't know if you can enlighten me any further.

Hopefully thanks in advance.
Jan 4 '07 #3
NeoPa
32,556 Expert Mod 16PB
1. Open the report in Design View.
2. Open the Properties Window (Alt-Enter).
3. Enter the name of the QueryDef (or the SQL string instead if you prefer) into the Record Source property.
Your report is now bound to the dataset specified and you can bind individual controls to the fields in the dataset.
Jan 4 '07 #4
feets
8
I think I need to explain things better. First of all thanks for all your advice so far.
I am connecting to a SQL Backend from an access Front End.mdb file. Now from my reading, binding a report to a recordset isn't available unless it is an Adp file.

I've created an Adp file, imported all my forms and reports from my MDB frontend, and like you say I can statically set the RecordSource to the stored procedure.

However, I want to set the RecordSource through Code

Set Me.RecordSource = Rs

yet it still says that it is an invalid use of property

I must be getting on your nerves but I could really use your advice!!
Jan 4 '07 #5
NeoPa
32,556 Expert Mod 16PB
I am connecting to a SQL Backend from an access Front End.mdb file. Now from my reading, binding a report to a recordset isn't available unless it is an Adp file.
I don't know what you're reading - I do it all the time and I only ever use .MDBs. Is there any qualification there that might make it all make sense?
I've created an Adp file, imported all my forms and reports from my MDB frontend, and like you say I can statically set the RecordSource to the stored procedure.

However, I want to set the RecordSource through Code

Expand|Select|Wrap|Line Numbers
  1. Set Me.RecordSource = Rs
yet it still says that it is an invalid use of property
I don't know about ADPs but in Access (MDB) you would put that code (assuming RS has already been set to a valid, and matching, recordset) in the form's OnOpen event.
Jan 4 '07 #6
feets
8
I don't know what you're reading - I do it all the time and I only ever use .MDBs. Is there any qualification there that might make it all make sense?

I don't know about ADPs but in Access (MDB) you would put that code (assuming RS has already been set to a valid, and matching, recordset) in the form's OnOpen event.
This is an extract from the Microsoft White Paper

USING ADO RECORDSETS WITH MICROSOFT ACCESS REPORTS
In Microsoft Access 2002, it is now possible to use ADO recordsets with reports in Microsoft Access project files. Unfortunately, the use of the report Recordset property is limited to project files. If you try to set or retrieve a report's Recordset property in a Jet database (.mdb) file, you receive the following error message:

Feature is not available in an MDB

I've attached my code used when opening the report - since I thought that it would make more sense.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.  
  3. ' Retrieve family details by entering FamilyID
  4.  
  5. Dim Rs As ADODB.Recordset ' Recordset produces a virtual table from SELECT query
  6.  
  7. Dim FolderName, PicName As String
  8. Dim strFamilyName, strAddress, strPostCode As String
  9.  
  10. Forms!frmWfsFamilyUpdate!txtFosterID.SetFocus
  11.  
  12. strFamilyID = Forms!frmWfsFamilyUpdate!txtFosterID.text
  13.  
  14. ' Open a SQL Connection, to use a SELECT stored procedure.
  15.  
  16. sqlConnect
  17.  
  18. Set cmd = New ADODB.Command
  19. cmd.ActiveConnection = Con
  20. cmd.CommandType = adCmdStoredProc
  21. cmd.CommandText = "selectFamilyDetails"
  22.  
  23. ' CarerID variable inputted into
  24. cmd.Parameters.Append cmd.CreateParameter("carerID", adVarChar, adParamInput, 8, strFamilyID)
  25.  
  26. ' Run Stored Procedure
  27. Set Rs = cmd.Execute
  28.  
  29. ' If Recordset is not at end of file. Assign Report Controls to RS fieldNames
  30.  
  31. If Not Rs.EOF Then
  32.     strFamilyName = Rs.Fields(2)
  33.     strAddress = Rs.Fields(3)
  34.     strAddress = strAddress & "," & Rs.Fields(4)
  35.     strAddress = strAddress & "," & Rs.Fields(5)
  36.     strPostCode = Rs.Fields(6)
  37.     strPostCode = strPostCode & " " & Rs.Fields(7)
  38.     strPhoneNo = Rs.Fields(8)
  39.  
  40. End If
  41.  
  42. strFamilyName = txtFamilyName
  43. strAddress = txtAddress
  44. strPostCode=txtPostCode
  45. strPhoneNo=txtPhoneNo
  46.  
  47.  
  48. End Sub
Jan 4 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
This is an extract from the Microsoft White Paper

USING ADO RECORDSETS WITH MICROSOFT ACCESS REPORTS
In Microsoft Access 2002, it is now possible to use ADO recordsets with reports in Microsoft Access project files. Unfortunately, the use of the report Recordset property is limited to project files. If you try to set or retrieve a report's Recordset property in a Jet database (.mdb) file, you receive the following error message:

Feature is not available in an MDB

I've attached my code used when opening the report - since I thought that it would make more sense.


Private Sub Report_Open(Cancel As Integer)

' Retrieve family details by entering FamilyID

Dim Rs As ADODB.Recordset ' Recordset produces a virtual table from SELECT query

Dim FolderName, PicName As String
Dim strFamilyName, strAddress, strPostCode As String

Forms!frmWfsFamilyUpdate!txtFosterID.SetFocus

strFamilyID = Forms!frmWfsFamilyUpdate!txtFosterID.text

' Open a SQL Connection, to use a SELECT stored procedure.

sqlConnect

Set cmd = New ADODB.Command
cmd.ActiveConnection = Con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "selectFamilyDetails"

' CarerID variable inputted into
cmd.Parameters.Append cmd.CreateParameter("carerID", adVarChar, adParamInput, 8, strFamilyID)

' Run Stored Procedure
Set Rs = cmd.Execute

' If Recordset is not at end of file. Assign Report Controls to RS fieldNames

If Not Rs.EOF Then
strFamilyName = Rs.Fields(2)
strAddress = Rs.Fields(3)
strAddress = strAddress & "," & Rs.Fields(4)
strAddress = strAddress & "," & Rs.Fields(5)
strPostCode = Rs.Fields(6)
strPostCode = strPostCode & " " & Rs.Fields(7)
strPhoneNo = Rs.Fields(8)

End If

strFamilyName = txtFamilyName
strAddress = txtAddress
strPostCode=txtPostCode
strPhoneNo=txtPhoneNo


End Sub
You're using the Report open event when you should be using the report format event.

Mary
Jan 5 '07 #8
NeoPa
32,556 Expert Mod 16PB
I am connecting to a SQL Backend from an access Front End.mdb file. Now from my reading, binding a report to a recordset isn't available unless it is an Adp file.
I don't know what you're reading - I do it all the time and I only ever use .MDBs. Is there any qualification there that might make it all make sense?
I've created an Adp file, imported all my forms and reports from my MDB frontend, and like you say I can statically set the RecordSource to the stored procedure.

However, I want to set the RecordSource through Code

Expand|Select|Wrap|Line Numbers
  1. Set Me.RecordSource = Rs
yet it still says that it is an invalid use of property
I don't know about ADPs but in Access (MDB) you would put that code (assuming RS has already been set to a valid, and matching, recordset) in the form's OnOpen event.
I don't know what I was thinking to miss a gaping problem here.
You want to assign a value (String) to Me.RecordSource (NOT Me.RecordSet) in the Open event of the report. You cannot assign RS to this as RS is not a string.
Jan 5 '07 #9

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

Similar topics

1
by: Joris Kempen | last post by:
Hi people, I know that the question has come around sometimes: How to open an Access Report using ASP and export it to for example RTF. I'm trying to implement the first method of David...
7
by: JMCN | last post by:
Is this possible to have the 97 users with 97 front end, 2000 users with 2000 front end, 2002 users with 2002 front end, and 2003 users with 2003 front end all linked up to an access 97 backend? ...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
5
by: Steven Taylor | last post by:
Hope someone can help. I have an application whereby in order to create one document type I effectively print out 3 or 4 access reports in correct order. So the user goes to the printer,...
1
by: Brian Barnes | last post by:
I've been searching using google trying to find a way to display Access Reports via ASP.NET and only finding commericial products which appear to require that the report needs to be converted every...
1
by: David | last post by:
Does anyone know how to run MS Access reports from VB.net. I'd like to keep the existing reports in the database if I can. Thanks David
0
by: dkurtz | last post by:
D. Lesandrini published an article some time ago about exporting Access reports as XML, and then updating those XML reports dynamically in ..NET....
16
by: JoeW | last post by:
I'm utilizing a database that I created within MS Access within a program I've created in VB.NET. I am using the VB front end to navigate the information, but want to be able to print a report,...
1
by: NeoDeGenero | last post by:
I have a little VBA/Access - Reports problem and I’m not sure on how to approach it: I am trying to send a Report generated by MS Access via email through the command SendObject. ...
1
by: anjee | last post by:
Hello all, We are in the process of rewriting a large application that uses an Access 2003 backend database. Unfortunately we will be building and releasing the application in phases which means...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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
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...

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.