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

Call a SQL Server Procedure from Access

How do I call a SQL Server Stored Procedure from a form in Access?

Thanks in advance!

chfran
Nov 12 '05 #1
3 15683
DFS
Create a pass-through query to your SQL system, fill in the ODBC info,
(optionally) set ReturnsRecords to No, and send the statement:

EXEC procName(args)

"chfran" <ch****@yahoo.com> wrote in message
news:9a**************************@posting.google.c om...
How do I call a SQL Server Stored Procedure from a form in Access?

Thanks in advance!

chfran

Nov 12 '05 #2
You can use the ADO command object as follows:

Dim cmd As New ADODB.Command, RSado As New ADODB.Recordset
Dim RSdao As DAO.Recordset, i As Integer

cmd.ActiveConnection = "Provider=SQLOLEDB;Data Source=S:" _
& "Initial Catalog=db1;UID=SA;PWD=;"
cmd.CommandTimeout = 600
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "yourSP"
cmd.Parameters("@bDate").Value = sDate
cmd.Parameters("@eDate").Value = eDate
Set RSado = cmd.Execute
Set RSdao = CurrentDb.OpenRecordset("tbl1")
Do While Not RSado.EOF
RSdao.AddNew
For i = 0 To RSado.Fields.Count - 1
RSdao(i) = RSado(i)
Next
RSdao.Update
RSado.MoveNext
Loop
RSdao.Close
RSado.Close
cmd.ActiveConnection.Close

I added parameters here (because my sp's all have params). I pull a
recordset from sql server and then copy it to a local DAO recordset
(tbl1). I do this in Access97 and it is very fast.

With ADO.net you don't even need a do loop. You can use Insert Into (or
select into) directly from the dataset object.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
On 9 Jan 2004 12:33:17 -0800, chfran wrote:
How do I call a SQL Server Stored Procedure from a form in Access?


As PassThrough from VBA:

Dim qrySP As QueryDef
Set qrySP = CurrentDb.CreateQueryDef("")
With qrySP
.Connect = "ODBC;Driver={SQL Server};Server=..."
.ReturnsRecords = False
.SQL = "YourProc"
.Execute dbSQLPassThrough
.Close
End With
Set qrySP = Nothing

Peter

--
No mails please.
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Davinder | last post by:
I am trying to invoke the following line of code within my ASP: Set oApp = Server.CreateObject("Word.Application") This results in the following error: ASP 0178 Server.CreateObject Access...
0
by: ninth | last post by:
hi: in mysql 5.0,how can i call a procedure in c?
3
by: Laurence Nuttall | last post by:
How can I call a control procedure call Timer1_Elapsed() I get : Argument not specified for paramter 'e' of Private sub_Timer1_Elapsed(sender as Object, e as System.timers.ElapsedEventArgs)...
2
by: ABHIJITghosh | last post by:
Hi, I like to call a procedure of oracle from VB 6. How can I do it? help me. Thank you. Abhijit Ghosh
5
kaleeswaran
by: kaleeswaran | last post by:
Hi! can i call the procedure inside the trigger?.... thank you, kaleeswaran
5
nev
by: nev | last post by:
if i add a new class1 in my program and i placed a public sub procedure in it, how will i call the procedure from form1? please help me find a link that answers this or please answer if you can....
2
by: nerurmon | last post by:
Hi, I want to call a procedure like cmd_Add_Click which I used in VB6 Call cmd_Add_Click What will be the command in VS2005 if I want to call same procedure? Please help me
1
by: JB | last post by:
I have a stored procedure being called from a C# program which is selecting a row from a table, processing a few of the fields, then I need to pass this back to the app. The original program it...
3
akashazad
by: akashazad | last post by:
Hi Friends My question is "can we call Stored Procedure from a User Defined Function in SQL" If yes then pl tell me how? If No then pl tell me why not ? While I was trying finding...
0
by: Kozy | last post by:
Hello everyone, I have a problem with a procedure that is calling another procedure. Pasting some code: INSERT INTO LOGGING.POTRDITEV_FAKTURE(A,B,C) VALUES(4, 'POTRDITEV_FAKTURE_DODATEK ZA...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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
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...

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.