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. - Dim sDate As String
-
Dim eDate As String
-
Dim rsbatf As New ADODB.Recordset
-
-
sDate = InputBox("Enter Beginning Period", "Beginning Period")
-
eDate = InputBox("Enter Ending Period", "Ending Period")
-
-
Set GetProc = New ADODB.Command
-
cn.CursorLocation = adUseServer
-
Set GetProc.ActiveConnection = cn
-
GetProc.CommandType = adCmdStoredProc
-
GetProc.CommandText = "dbo.FreightCostAdjustments"
-
GetProc.Parameters("@startPeriod").Value = sDate
-
GetProc.Parameters("@endPeriod").Value = eDate
-
Set rsbatf = GetProc.Execute
-
Me.RecordSource = rsbatf
can anyone help please.
17 21179 Rabbit 12,516
Recognized Expert Moderator MVP
GetProc doesn't seem to be defined.
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 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. - Dim sDate As String
-
Dim eDate As String
-
Dim rsbatf As New ADODB.Recordset
-
-
sDate = InputBox("Enter Beginning Period", "Beginning Period")
-
eDate = InputBox("Enter Ending Period", "Ending Period")
-
-
Set GetProc = New ADODB.Command
-
cn.CursorLocation = adUseServer
-
Set GetProc.ActiveConnection = cn
-
GetProc.CommandType = adCmdStoredProc
-
GetProc.CommandText = "dbo.FreightCostAdjustments"
-
GetProc.Parameters("@startPeriod").Value = sDate
-
GetProc.Parameters("@endPeriod").Value = eDate
-
Set rsbatf = GetProc.Execute
-
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: - Dim rsbatf As New ADODB.Recordset
-
'should be
-
Dim rsbatf As ADODB.Recordset
-
Set rsbatf As New ADODB.Recordset
-
-
Set GetProc = New ADODB.Command
-
'should be
-
Dim GetProc As ADODB.Command
-
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: - 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: - 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.
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: - Dim rsbatf As New ADODB.Recordset
-
'should be
-
Dim rsbatf As ADODB.Recordset
-
Set rsbatf As New ADODB.Recordset
-
-
Set GetProc = New ADODB.Command
-
'should be
-
Dim GetProc As ADODB.Command
-
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: - 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: - 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.
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.
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. -
If Application.Version >= 11# Then
-
Application.AutomationSecurity = 1 ' msoAutomationSecurityLow
-
End If
I tried it this way an it works ok. - Private Sub Report_Open(Cancel As Integer)
-
Dim cmd As ADODB.Command
-
Set cmd = New ADODB.Command
-
-
cmd.ActiveConnection = Application.CurrentProject.Connection
-
cmd.CommandType = adCmdStoredProc
-
cmd.CommandText = "Name of the Store Procedure"
-
-
'Your parameters
-
cmd.Parameters("@startdate").Value = "1/1/1"
-
cmd.Parameters("@finaldate").Value = "7/7/7"
-
-
Set Me.Recordset = cmd.Execute
-
End Sub
I hope it helps...
ADezii 8,834
Recognized Expert Expert
I tried it this way an it works ok. - Private Sub Report_Open(Cancel As Integer)
-
Dim cmd As ADODB.Command
-
Set cmd = New ADODB.Command
-
-
cmd.ActiveConnection = Application.CurrentProject.Connection
-
cmd.CommandType = adCmdStoredProc
-
cmd.CommandText = "Name of the Store Procedure"
-
-
'Your parameters
-
cmd.Parameters("@startdate").Value = "1/1/1"
-
cmd.Parameters("@finaldate").Value = "7/7/7"
-
-
Set Me.Recordset = cmd.Execute
-
End Sub
I hope it helps...
In your workable code, the ActiveConnectio n Property of the Command Object is clearly defined as in: - cmd.ActiveConnection = Application.CurrentProject.Connection
whereas in your non-workable version: - Set GetProc.ActiveConnection = cn 'what does cn point to
try - Set GetProc.ActiveConnection = CurrentProject.Connection
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: - cmd.ActiveConnection = Application.CurrentProject.Connection
whereas in your non-workable version: - Set GetProc.ActiveConnection = cn 'what does cn point to
try - Set GetProc.ActiveConnection = CurrentProject.Connection
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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...
|
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®ards!
Peter
|
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
| |
by: Nitin Kshirsagar |
last post by:
how to use stored procedure in ms-access through the vb6.0?
|
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
|
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...
|
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?
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |