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 21098
GetProc doesn't seem to be defined.
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
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.CursorLocation = 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.ActiveConnection = cn. cn should refer to a Connection Object - where? __4. GetProc.CursorLocation = 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.RecordSource = 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.CursorLocation = 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.ActiveConnection = cn. cn should refer to a Connection Object - where? __4. GetProc.CursorLocation = 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,556
Expert Mod 16PB
I have tried some of the changes you told. But I am still getting the same compilation error at the line "Me.RecordSource = 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.
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
BoundObjectFrame Object
Combobox Recordset
Control Object
CurrentProject AccessConnection, BaseConnectionString, CloseConnection, Connection, OpenConnection
CustomControl Object
Form Dynaset
Hyperlink Add to favorites
Listbox Recordset
ObjectFrame Object Report Recordset
SmartTagAction Execute
Screen ActiveDataAccessPage
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...
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 ActiveConnection 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 ActiveConnection 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
I performed a major Face Lift on the code and I think this will work. Let me know how you make out (Open() Event of Report). - Private Sub Report_Open(Cancel As Integer)
-
Dim sDate As String, eDate As String
-
-
sDate = InputBox("Enter Beginning Period", "Beginning Period")
-
eDate = InputBox("Enter Ending Period", "Ending Period")
-
-
'Cannot be Empty Strings or Nulls
-
If Len(sDate) = 0 Or Len(eDate) = 0 Then
-
Cancel = True
-
Exit Sub
-
End If
-
-
'Must be valid Dates
-
If Not IsDate(sDate) Or Not IsDate(eDate) Then
-
Cancel = True
-
Exit Sub
-
End If
-
-
Dim GetProc As ADODB.Command
-
Set GetProc = New ADODB.Command
-
-
With GetProc
-
'automatically maintained for *.adps
-
.ActiveConnection = CurrentProject.Connection
-
.CommandType = adCmdStoredProc
-
.CommandText = "dbo.FreightCostAdjustments"
-
.Parameters("@startPeriod").Value = sDate
-
.Parameters("@endPeriod").Value = eDate
-
End With
-
-
Set Me.Recordset = GetProc.Execute
-
Set GetProc = Nothing
-
End Sub
I am very thank ful to you.
I think the error might be the access problem, It likes the whole code except Set Me.Recordset = GetProc.Execute .
Getting the same error This feature is not available in an MDB, Run-time error '2593'. Can you figure out that.....please
Thanks again for spending your valuable time on this problem. I performed a major Face Lift on the code and I think this will work. Let me know how you make out (Open() Event of Report). - Private Sub Report_Open(Cancel As Integer)
-
Dim sDate As String, eDate As String
-
-
sDate = InputBox("Enter Beginning Period", "Beginning Period")
-
eDate = InputBox("Enter Ending Period", "Ending Period")
-
-
'Cannot be Empty Strings or Nulls
-
If Len(sDate) = 0 Or Len(eDate) = 0 Then
-
Cancel = True
-
Exit Sub
-
End If
-
-
'Must be valid Dates
-
If Not IsDate(sDate) Or Not IsDate(eDate) Then
-
Cancel = True
-
Exit Sub
-
End If
-
-
Dim GetProc As ADODB.Command
-
Set GetProc = New ADODB.Command
-
-
With GetProc
-
'automatically maintained for *.adps
-
.ActiveConnection = CurrentProject.Connection
-
.CommandType = adCmdStoredProc
-
.CommandText = "dbo.FreightCostAdjustments"
-
.Parameters("@startPeriod").Value = sDate
-
.Parameters("@endPeriod").Value = eDate
-
End With
-
-
Set Me.Recordset = GetProc.Execute
-
Set GetProc = Nothing
-
End Sub
I am very thank ful to you.
I think the error might be the access problem, It likes the whole code except Set Me.Recordset = GetProc.Execute .
Getting the same error This feature is not available in an MDB, Run-time error '2593'. Can you figure out that.....please
Thanks again for spending your valuable time on this problem.
I think that I may finally have the solution, if I am correct you are unfortunately in trouble unless you upgrade.
The capability of setting a Report's Recordset Property programmatically is NEW in Access 2002.
If you are using a Version of Access prior to 2002, you are in trouble. Let me know how you make out.
I am using access 2000. But if I kept a "record set" , instead of me.recordset like the following.
set rsbatf = GetProc.Execute
Now I can access the return values into variables of report in code.
But my problem is how do I get the values of variables into report controls(text boxes or labels).Is there any way to get the report variables into report controls.
Thanks I think that I may finally have the solution, if I am correct you are unfortunately in trouble unless you upgrade. If you are using a Version of Access prior to 2002, you are in trouble. Let me know how you make out.
I am using access 2000. But if I kept a "record set" , instead of me.recordset like the following.
set rsbatf = GetProc.Execute
Now I can access the return values into variables of report in code.
But my problem is how do I get the values of variables into report controls(text boxes or labels).Is there any way to get the report variables into report controls.
Thanks
Once a Recordset has been create via GetProc.Execute, you should be able to treat it like any other Recordset, namely: - Set rsbatf = GetProc.Execute
-
rsbatf.MoveLast: rsbatf.MoveFirst
-
-
Debug.Print rsbatf.RecordCount 'will give your the Number of Records
-
-
With rsbatf
-
Do While Not .EOF 'loop through all the Records
-
Debug.Print ![Field1]
-
Debug.Print ![Field2]
-
Debug.Print ![Field3]
-
Debug.Print ![...]
-
.MoveNext
-
Loop
-
End With
-
-
rsbatf.Close
But my problem is how do I get the values of variables into report controls(text boxes or labels).Is there any way to get the report variables into report controls.
Is your question how do I now populate the Fields (Labels and Text Boxes) in the Detail Section with appropriate values from the Recordset? If this is correct, then the mechanism to do this is probably very complex, which is probably why this capability didn't exist until Access 2002. An off-the-wall solution would be to add all the Records from the Recordset (rsbatf) to a Table which would then be the RecordSource for the Report. I think that I would hold off on this approach for awhile and see if someone comes up with a better solution. If you do want to take this unorthodox approach, I'll need the Field Names in the rsbatf Recordset as well as their Data Types and the Name of the Table which will be the RecordSource for the Report.
Yes, I did the same. I sent all the values into temporary variables and then used those values to populate labels on the report. But in this process it is not allowing textboxes to populate.
Until I get better solution, I will keep this code.
Thanks a lot for spending your valuble time on this problem. With out your code I may not able to get the record set. Once a Recordset has been create via GetProc.Execute, you should be able to treat it like any other Recordset, namely: - Set rsbatf = GetProc.Execute
-
rsbatf.MoveLast: rsbatf.MoveFirst
-
-
Debug.Print rsbatf.RecordCount 'will give your the Number of Records
-
-
With rsbatf
-
Do While Not .EOF 'loop through all the Records
-
Debug.Print ![Field1]
-
Debug.Print ![Field2]
-
Debug.Print ![Field3]
-
Debug.Print ![...]
-
.MoveNext
-
Loop
-
End With
-
-
rsbatf.Close
Is your question how do I now populate the Fields (Labels and Text Boxes) in the Detail Section with appropriate values from the Recordset? If this is correct, then the mechanism to do this is probably very complex, which is probably why this capability didn't exist until Access 2002. An off-the-wall solution would be to add all the Records from the Recordset (rsbatf) to a Table which would then be the RecordSource for the Report. I think that I would hold off on this approach for awhile and see if someone comes up with a better solution. If you do want to take this unorthodox approach, I'll need the Field Names in the rsbatf Recordset as well as their Data Types and the Name of the Table which will be the RecordSource for the Report.
Yes, I did the same. I sent all the values into temporary variables and then used those values to populate labels on the report. But in this process it is not allowing textboxes to populate.
Until I get better solution, I will keep this code.
Thanks a lot for spending your valuble time on this problem. With out your code I may not able to get the record set.
It's a shame that you can't upgrade to Access 2002, we wouldn't even be having this conversation.
Hi,
I'm trying to use the same functionality in my report.
I tried the code it works fine within Report_Open sub but when it comes to attach the controls(text boxes in the Detail Section) in the report with the recordset. It does not shows the records but a blank report. Is there something that needs to be done to attach to controls.
Thanks,
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...
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...
|
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...
|
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...
|
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!...
|
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...
|
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...
|
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...
|
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?...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |