Currently i am working in a project of report generation in MS ACCESS.
The tables are in sql server 2000.
I have to write stored proc in ms access.
Illustration:
I am having a stored proc as follows
name: myproc
-------------------
Create procedure my_proc
@f1 char(1),
@f2 char(5)
As
select * from table1 where field1=@f1 and field2=@f2
________________________________________________
and calling proc
name: call_myproc
execute my_proc 'A','2004'
It works fine. I have got all the values which satisfies the above condition in report.
If i am getting the vales of field1 and field2 from forms (form_a) in ms access.
I have to write the calling proc as follows
my_proc [forms]![form_a].[Combo4],[forms]![form_a].[text12]
But ms access throws syntax error.
How is it possible to pass values from ms access FORMS to a calling stored procedure.
could you please help me to fix this problem ?
14 8057
Access requires single quotes surrounding string values passed this way.
my_proc "'" & [forms]![form_a].[Combo4] & "'", "'" & [forms]![form_a].[text12] & "'"
Currently i am working in a project of report generation in MS ACCESS.
The tables are in sql server 2000.
I have to write stored proc in ms access.
Illustration:
I am having a stored proc as follows
name: myproc
-------------------
Create procedure my_proc
@f1 char(1),
@f2 char(5)
As
select * from table1 where field1=@f1 and field2=@f2
________________________________________________
and calling proc
name: call_myproc
execute my_proc 'A','2004'
It works fine. I have got all the values which satisfies the above condition in report.
If i am getting the vales of field1 and field2 from forms (form_a) in ms access.
I have to write the calling proc as follows
my_proc [forms]![form_a].[Combo4],[forms]![form_a].[text12]
But ms access throws syntax error.
How is it possible to pass values from ms access FORMS to a calling stored procedure.
could you please help me to fix this problem ?
PEB 1,418
Expert 1GB
Yeap,
Interesting, nevetr knew that in Access project you can use the stored procedures in SQL Server... Never tried!
But sounds like Access is done for interface of SQL Server :)
I've read somhere that Access is the second one application used for user interface with Oracle After the Oracle offered interface!
What do you think about???
:)
Yeap,
Interesting, nevetr knew that in Access project you can use the stored procedures in SQL Server... Never tried!
But sounds like Access is done for interface of SQL Server :)
I've read somhere that Access is the second one application used for user interface with Oracle After the Oracle offered interface!
What do you think about???
:)
Access is ideal as a GUI for sql databases because to a great extent it is designed to be used that way.
The thing to remember when passing stored procedures is to use the syntax of the backend server for all sql rather than Access sql.
You can also create what are known as pass thru sql queries in access once you have an odbc connection to the server. These are sql queries written in the sql syntax of the applications backend and are executed directly on the backend rather than relying on frontend links.
The stored procedure feature simply requires you to create a connection in vba to the backend and .Execute the procedure as in the aforementioned example.
I'm sure some of our other experts will have a lot more knowledge on the subject.
Mary
PEB 1,418
Expert 1GB
Thanks Mary for the info,
Maybe here is important to not confuse the SQL standarts... Coz SQL Server uses SQL92 till Access ordinary uses SQL89
But using a VB procedures should be run locally from Access and the Query should be written on SQL 89 isn't it?
NeoPa 32,534
Expert Mod 16PB
You can access SQL Server tables from Access straightforwardly if they are linked.
To access (use) native SQL Server facilities like SPs (Stored Procedures) and UDFs (User Defined Functions) you need to program Pass-Through queries.
Pass-Through queries are written in the native language of the system connected to (in other words, for MS SQL Server Transact-SQL).
Pass-Through queries run as if they were on the SQL Server itself - hence can access SPs & UDFs without a problem.
PEB 1,418
Expert 1GB
Thanks Adrian,
So if the query isn't Pass trou, so it is executed locally by the Access Jet database engine. Ok now clear!
Thanks a lot my friends :)
NeoPa 32,534
Expert Mod 16PB
That's absolutely right PEB - You've got it.
Thank you very much for your response.
I am creating and executing the stored procedure in the same way as given in the following link. http://www.databasejournal.com/featu...0895_3363511_3
I have tried by giving like this. - EXECUTE call_RSM_Query "'"&[forms]![rsm_form].[Combo0]&"'","'"&[forms]![rsm_form].[Combo6]&"'","'"&[forms]![rsm_form].[Combo8]&"'","'"&[forms]![rsm_form].[text62]&"'","'"&[forms]![rsm_form].[text63]&"'","'"&[forms]![rsm_form].[text57]&"'","'"&[forms]![rsm_form].[text58]&"'", "'"&[forms]![rsm_form].[text59]&"'","'"&[forms]![rsm_form].[text60]&"'"
It throws the following error.
PLA daily report
ODBC--call failed.
[Microsoft][ODBC SQL Server Driver][SQL Server] Line 1: Incorrect syntax near '&' #170
I think the problem is with the syntax. What is the correct syntax to pass values from forms to a calling stored proc.
NeoPa 32,534
Expert Mod 16PB
Check out the Help for Execute to see how it should be used. Execute Method
Runs an action query or executes an SQL statement on a specified Connection or Database object.
Syntax
object.Execute source, options
querydef.Execute options
The Execute method syntax has these parts.
Part Description object A Connection or Database object variable on which the query will run. querydef An object variable that represents the QueryDef object whose SQL property setting specifies the SQL statement to execute. source A String that is an SQL statement or the Name property value of a QueryDef object. options Optional. A constant or combination of constants that determines the data integrity characteristics of the query, as specified in Settings.
Thank you very much for your response.
I am creating and executing the stored procedure in the same way as given in the following link. http://www.databasejournal.com/featu...0895_3363511_3
Ok you are trying to design the Execute in the Pass thru sql query window. I thought you were using vba.
Can you give an example of what the query would look like if you used values instead of the combo box.
When I give like this. The calling proc executes fine. I got the output.
execute my_proc 'A','2004'.
__________________________________________________ ________
example.
-------------
let me explain elaborately.
-------------------------------------
I have created a form named [Form3] consists of combo box "Department" values (eee,ece,mech,cse). and I created a table in SQL Server named register consists of the fields stud_name, register_num,mark1,mark2,mark3. And I am having a query query1. "select * from dbo.register where department=[forms]![form3].[combo3]. And I am having a report Report1, will display Name, mark1, mark2, mark3.
When the user chooses the department as "ece".
The report1 will be generated consists of the all the "ece" students names and their marks.
It works fine.
Now i need to do it with stored procedure.
I wrote a stored procedure as follows.
name of the pass through query: my_proc
-------------------------------
create procedure str_proc
@dept
as
select stud_name,mark1,mark2,mark3 from dbo.register where department=@dept
-----------------------------
and executed this pass through query. I did not get any errors.
I wrote another-pass through query as follows.
execute str_proc 'ece'
I got all the values (name and marks)
I gave it like
execute str_proc [form]![form3].[ combo3]
It throws error message.
Then i have given the following code in the report1 - on open event.[Event Procedure]
------------------------
Dim cnn as ADODB.Connection
Dim sqlstr as String
sqlstr = "execute str_proc (" & [forms]![form3]![combo3 & ");"
set cnn = new ADODB.Connection
with cnn
.ConnectionString = globalDS
.Open
.Execute(sqlstr)
.Close
end with
set cnn = nothing
--------------------------
But still values of name,mark1,mark2, mark3 not populating in the text boxes on the report1. what is the solution for this problem.
could you please help me to fix this problem.
I gave it like
execute str_proc [form]![form3].[ combo3]
It throws error message.
You can't do this directly in the pass thru window as [form]![form3].[ combo3] means nothing outside of Access and you are trying to execute directly on the server
You could try something like this ... -
-
Dim conn As New ADODB.Connection
-
Dim cmd As New ADODB.Command
-
-
conn.ConnectionString = globalDS
-
conn.Open
-
-
cmd.CommandText = "str_proc '" & [Forms]![form3]![combo3] & "'"
-
cmd.CommandType = adCmdStoredProc
-
cmd.ActiveConnection = conn
-
cmd.Execute
-
-
conn.Close
-
-
But the values are not populating in the report.
eg.
I am having report like this
stud_name Mark1 Mark2 Mark3
_________ _____ ____ ____
| | | | | | | | ----> text boxes.
----------------- ---------- -------- --------
but the values are not populating in the corresponding textboxes.
what should i have to do?
I have given ur coding in report on open event !! is that correct ?
or i have to give ur coding in the form button event on click.
also I havenot given anything in the record source of report properties.
how to proceed furthur.
NeoPa 32,534
Expert Mod 16PB
If you are trying to run a report, then I can't see how executing the SP remotely will help at all.
Execute runs an action query. Even if it returns results, how do you get the report to use them?
You need to design a Pass-through query in access which references the form control.
This will be like a template but will be changed every time you run it. Set the Tag to be the template SQL with a marker that needs changing for every instance. When you want to run it, update the SQL by getting the Tag SQL data and updating the marker with the current value required (in your VBA code). Save this in the SQL property of the query.
Set the reports Data Source property to this query and all should be well.
NB Formatting is never performed on the Pass-through query results so if you want to test the data beforehand, bear this in mind.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lauren Quantrell |
last post by:
I'm using an Access2K front end on a SQL Server2K backend.
I use Scope_Identity() in a lot of stored procedures to pass the
newwly inserted record's unique ID to the next select statement in the...
|
by: Nelson Xu |
last post by:
Hi All
Does anyone knows how to pass an array from .net application to oracle stored procedure
Thank you in advance
Nelson
|
by: Jeff Thur |
last post by:
I am running a SQL Stored Procedure that will give the
user a count of how many records are in the database as
per certain criteria.
I'm using the Execute Scalar Method.
I have no problem passing...
|
by: randy.p.ho |
last post by:
Using JDBC, is there a way to call a stored procedure with multiple
return values? Thanks.
|
by: Mark Dicken |
last post by:
Hi All
I have found the following Microsoft Technet 'Q'
Article :-
Q210368 -ACC2000: How to Pass an Array as an Argument to a Procedure
(I've also copied and pasted the whole contents into...
|
by: Zlatko Matić |
last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the...
|
by: Yoshitha |
last post by:
hi all
i created a stored procedure like this which retruns values am not sure
whether it is correct
or not.
if it is wrong can you tell me where i did mistake.
CREATE PROCEDURE...
|
by: scparker |
last post by:
Hello,
We have a stored procedure that does a basic insert of values. I am
then able to retrieve the ID number created for this new record. We are
currently using ASP.NET 2.0 and use N-Tier...
|
by: roshnair |
last post by:
Hi i have a small problem . I need to change one query to stored procedure and call it in my vb.net application.Query is :
Select * from emp where empid in (‘001’,’002’)
For this query I...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |