473,625 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing stored procedure as record source to access report

23 New Member
I have been using access as front end and SQL as Back end. I need help in generating an access report, by using a stored procedure with input parameters
as record source.
I tried the following code, but getting an error.Can't I use recordset as record source for the report.

Expand|Select|Wrap|Line Numbers
  1. Dim sDate As String
  2. Dim eDate As String
  3. Dim rsbatf As New ADODB.Recordset
  4.  
  5. sDate = InputBox("Enter Beginning Period", "Beginning Period")
  6. eDate = InputBox("Enter Ending Period", "Ending Period")
  7.  
  8.       Set GetProc = New ADODB.Command
  9.         cn.CursorLocation = adUseServer
  10.         Set GetProc.ActiveConnection = cn
  11.         GetProc.CommandType = adCmdStoredProc
  12.         GetProc.CommandText = "dbo.FreightCostAdjustments"
  13.         GetProc.Parameters("@startPeriod").Value = sDate
  14.         GetProc.Parameters("@endPeriod").Value = eDate
  15.         Set rsbatf = GetProc.Execute
  16.     Me.RecordSource = rsbatf
can anyone help please.
Apr 10 '07 #1
17 21179
Rabbit
12,516 Recognized Expert Moderator MVP
GetProc doesn't seem to be defined.
Apr 12 '07 #2
Denburt
1,356 Recognized Expert Top Contributor
I have never tried to set a recordsource based on a recordset.... It has been a long day and although I have a lot of experience in each app I don't have a lot of experience utilizing SQL server from MS Access. It would seem to me that you need a difinitive view or SQl statement from SQL server then you should be O.K.

Forms
Forms and Reports in Access derive their data from queries or SELECT statements bound to the RecordSource property. In the client/server environment, the RecordSource property is based on a server-based view or on a stored procedure that is expected to return the same data as the original Access query. When you convert the record source, the same rules apply as for queries (see "Migrating Access Queries" earlier in this chapter).
http://www.microsoft.com/technet/pro....mspx?mfr=true
Apr 12 '07 #3
ADezii
8,834 Recognized Expert Expert
I have been using access as front end and SQL as Back end. I need help in generating an access report, by using a stored procedure with input parameters
as record source.
I tried the following code, but getting an error.Can't I use recordset as record source for the report.

Expand|Select|Wrap|Line Numbers
  1. Dim sDate As String
  2. Dim eDate As String
  3. Dim rsbatf As New ADODB.Recordset
  4.  
  5. sDate = InputBox("Enter Beginning Period", "Beginning Period")
  6. eDate = InputBox("Enter Ending Period", "Ending Period")
  7.  
  8.       Set GetProc = New ADODB.Command
  9.         cn.CursorLocation = adUseServer
  10.         Set GetProc.ActiveConnection = cn
  11.         GetProc.CommandType = adCmdStoredProc
  12.         GetProc.CommandText = "dbo.FreightCostAdjustments"
  13.         GetProc.Parameters("@startPeriod").Value = sDate
  14.         GetProc.Parameters("@endPeriod").Value = eDate
  15.         Set rsbatf = GetProc.Execute
  16.     Me.RecordSource = rsbatf
can anyone help please.
There is a lot to review before you even get to the Report aspect:

__1. It is an accepted programming practice not to Declare and Instantiate an Object Variable on the same line:
Expand|Select|Wrap|Line Numbers
  1. Dim rsbatf As New ADODB.Recordset
  2.                   'should be
  3. Dim rsbatf As ADODB.Recordset
  4. Set rsbatf As New ADODB.Recordset
  5.  
  6. Set GetProc = New ADODB.Command
  7.                   'should be
  8. Dim GetProc As ADODB.Command
  9. Set GetProc = New ADODB.Command
__2. cn.CursorLocati on = adUseServer. cn usually points to a Connection Object
and the Method to set up a Connection for this Command would be:
Expand|Select|Wrap|Line Numbers
  1. Set GetProc.ActiveConnection = CurrentProject.Connection
__3. Set GetProc.ActiveC onnection = cn. cn should refer to a Connection Object - where?
__4. GetProc.CursorL ocation = adUseServer. CursorLocation is a Property of a Recordset Object and is used accordingly:
Expand|Select|Wrap|Line Numbers
  1. MyRS.CursorLocation = adUseServer
__5. You are passing Parameters (sDate and eDate) to a Stored Procedure which probably requires a Date Data Type, yet they are declared as Strings.
Apr 12 '07 #4
kkk1979
23 New Member
I have tried some of the changes you told. But I am still getting the same compilation error at the line "Me.RecordSourc e = rsbatf " as "Type Mismatch" by highlighting ".RecordSource" .

Can't I put a recordset as RecordSource for the report ?

There is a lot to review before you even get to the Report aspect:

__1. It is an accepted programming practice not to Declare and Instantiate an Object Variable on the same line:
Expand|Select|Wrap|Line Numbers
  1. Dim rsbatf As New ADODB.Recordset
  2.                   'should be
  3. Dim rsbatf As ADODB.Recordset
  4. Set rsbatf As New ADODB.Recordset
  5.  
  6. Set GetProc = New ADODB.Command
  7.                   'should be
  8. Dim GetProc As ADODB.Command
  9. Set GetProc = New ADODB.Command
__2. cn.CursorLocati on = adUseServer. cn usually points to a Connection Object
and the Method to set up a Connection for this Command would be:
Expand|Select|Wrap|Line Numbers
  1. Set GetProc.ActiveConnection = CurrentProject.Connection
__3. Set GetProc.ActiveC onnection = cn. cn should refer to a Connection Object - where?
__4. GetProc.CursorL ocation = adUseServer. CursorLocation is a Property of a Recordset Object and is used accordingly:
Expand|Select|Wrap|Line Numbers
  1. MyRS.CursorLocation = adUseServer
__5. You are passing Parameters (sDate and eDate) to a Stored Procedure which probably requires a Date Data Type, yet they are declared as Strings.
Apr 16 '07 #5
NeoPa
32,567 Recognized Expert Moderator MVP
I have tried some of the changes you told. But I am still getting the same compilation error at the line "Me.RecordSourc e = rsbatf " as "Type Mismatch" by highlighting ".RecordSource" .

Can't I put a recordset as RecordSource for the report ?
No.
RecordSource is the name of a record source (A string). It cannot be set to a non-string VBA program variable. It wouldn't make sense if you think about it.
Apr 17 '07 #6
Denburt
1,356 Recognized Expert Top Contributor
Can't I put a recordset as RecordSource for the report ?
Something to look at:
http://office.microsoft.com/en-us/ac...CH100621891033

Properties blocked by sandbox mode

In addition to the functions listed in the previous section, sandbox mode also blocks a number of object properties. The following table lists the objects and the blocked property or properties for each object.

Use the links in the See Also section for more help for the most commonly used properties.
Object Blocked Property or Properties
BoundObjectFram e Object
Combobox Recordset
Control Object
CurrentProject AccessConnectio n, BaseConnectionS tring, CloseConnection , Connection, OpenConnection
CustomControl Object
Form Dynaset
Hyperlink Add to favorites
Listbox Recordset
ObjectFrame Object
Report Recordset
SmartTagAction Execute
Screen ActiveDataAcces sPage
Could be an issue...

Try reducing your Automation Security Level before setting the property.
Expand|Select|Wrap|Line Numbers
  1. If Application.Version >= 11# Then
  2.     Application.AutomationSecurity = 1 ' msoAutomationSecurityLow
  3. End If
Apr 17 '07 #7
Hans Payini
1 New Member
I tried it this way an it works ok.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.       Dim cmd As ADODB.Command
  3.       Set cmd = New ADODB.Command
  4.  
  5.       cmd.ActiveConnection = Application.CurrentProject.Connection
  6.       cmd.CommandType = adCmdStoredProc
  7.       cmd.CommandText = "Name of the Store Procedure"
  8.  
  9.       'Your parameters
  10.       cmd.Parameters("@startdate").Value = "1/1/1"
  11.       cmd.Parameters("@finaldate").Value = "7/7/7"
  12.  
  13.       Set Me.Recordset = cmd.Execute
  14. End Sub
I hope it helps...
May 8 '07 #8
ADezii
8,834 Recognized Expert Expert
I tried it this way an it works ok.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2.       Dim cmd As ADODB.Command
  3.       Set cmd = New ADODB.Command
  4.  
  5.       cmd.ActiveConnection = Application.CurrentProject.Connection
  6.       cmd.CommandType = adCmdStoredProc
  7.       cmd.CommandText = "Name of the Store Procedure"
  8.  
  9.       'Your parameters
  10.       cmd.Parameters("@startdate").Value = "1/1/1"
  11.       cmd.Parameters("@finaldate").Value = "7/7/7"
  12.  
  13.       Set Me.Recordset = cmd.Execute
  14. End Sub
I hope it helps...
In your workable code, the ActiveConnectio n Property of the Command Object is clearly defined as in:
Expand|Select|Wrap|Line Numbers
  1. cmd.ActiveConnection = Application.CurrentProject.Connection
whereas in your non-workable version:
Expand|Select|Wrap|Line Numbers
  1. Set GetProc.ActiveConnection = cn    'what does cn point to
try
Expand|Select|Wrap|Line Numbers
  1. Set GetProc.ActiveConnection = CurrentProject.Connection
May 8 '07 #9
kkk1979
23 New Member
Hi,
When I tried the statement
Me.Recordset = cmd.Execute
getting an error "THis feature is not available in an mdb".
But I can now able to get result into a record set(with your code). Thanks a lot for that. I am able to send the values into temporary variables but not into report controls.How do I get the values into report controls. Can you help me pls.

Thanks in advance


In your workable code, the ActiveConnectio n Property of the Command Object is clearly defined as in:
Expand|Select|Wrap|Line Numbers
  1. cmd.ActiveConnection = Application.CurrentProject.Connection
whereas in your non-workable version:
Expand|Select|Wrap|Line Numbers
  1. Set GetProc.ActiveConnection = cn    'what does cn point to
try
Expand|Select|Wrap|Line Numbers
  1. Set GetProc.ActiveConnection = CurrentProject.Connection
Jul 30 '07 #10

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

Similar topics

3
9007
by: kevin | last post by:
I have written a stored procedure (sp) that calculates the number of seats remaining for an event. I need to pass the event id to the sp. I have a combo box that lists all the events. When I choose the event from the combo box the event executes the sp and the 'Enter Parameter Value' box appears. How can I execute this sp and pass the value to it via vba and ms access and not have the input box appear? Also, how do return the value from...
4
2342
by: Magy | last post by:
What would be the best way to execute a Oracle stored procedure that excepts several input paramters, through a web method in vb.net. What would be a good way to get to the web method, the Oracle stored procedure's definition; the name of the proc. and all of the parameter information such as name, value, type and value. I'm looking for the best method. Any ideas. Magy
1
1642
by: Robert | last post by:
I have a form that has a table; tblProjects; as its record source. The form is filtered, however, by two combo boxes in the header. One allows the user to select a client, the other a project for that client. These two selections populate the form with info from that tblProjects table. I want to create a report that would contain the information from that form but I have no idea what my record source should be for the report so that it...
6
9894
by: Peter Neumaier | last post by:
Hi, I am trying to select some data through a stored procedure and would like to store the result in a local access table. Is that possible? Can somebody provide an example? Thanks&regards! Peter
0
971
by: benscribe | last post by:
Hi, I have a C# web page using a datagrid to display the results of a database query. I want to be able to pass arguments to the stored procedure inside the selectcommand asp tag, but the right syntax is eluding me. Any clues? Thanks, Ben
0
1165
by: Nitin Kshirsagar | last post by:
how to use stored procedure in ms-access through the vb6.0?
6
3477
by: SethM | last post by:
I have a stored procedure that returns a record set. I want to functionalize this so I can have multiple presentations of the same record set. However, I can not get rs_event.open StoreProc to pass through the function, so I can use rs_event("Title"), etc, etc. Is this possible to do? If so how? Thanks. Regards, Seth
0
1175
by: perdijc | last post by:
The wizard to create dataset, automatically creates a method to update table if the dataset is based on table. If i create a dataset based on sotored procedure where this is based on more one table, it doesn´t create the update method. Any bodyelse, knows any wizard or addin where i can create update method based on stored procedure? Im ms access project if I bound a form to stored procedure, in the properties form, I have option to...
1
1441
by: leec | last post by:
I need to populate an access table with the results from a SELECT stored procedure in SQL Server. 1. Is this possible? 2. If it is possible, can it all be part of the modified Stored Procedure? 3. What do I need to call to make this happen?
0
8182
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
8688
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...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
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
7178
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
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
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
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.