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

Passing Parameters to a stored Proc in access

5
I am a new bee to VBA. I have created an app which outputs the data from access to an Excel spread sheet and saves it. I have used the following snippet to perform that action. The following is the code that I have used, and it works fine. However, I have 2 questions

1. A security alert opens up every time I try to write in to the access database. How do I avoid that?
2. The "query1" in the following code is a stored proc in access, which requires a parameter (projnumber). Currently I have to manually type this projecId to pass it to the stored proc. How do I do it programatically?

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>

Dim strOutputPath As String
Set a = CreateObject("access.application")
a.OpenCurrentDatabase ("W:\Quality Assurance\QA document automation\Database\AutomationDocumentation.mdb")
'a.DoCmd.OpenQuery "Query1"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel3, "query1", "W:\Quality Assurance\QA document automation\Template\TestCaseManagement.xls", False
'a.DoCmd.Close
'a.Quit
Application.Workbooks.Open ("W:\Quality Assurance\QA document automation\Template\TestCaseManagement.xls")
Application.Visible = False
With Workbooks("TestCaseManagement.xls")
.SaveAs ("W:\Quality Assurance\QA document automation\Testcases\" & projnumber & ".xls")
End With

ThisWorkbook.Close (False)
Oct 8 '08 #1
7 1833
ADezii
8,834 Expert 8TB
You can use ADO and the Parameters Collection of a Command Objuect to pass Parameters to a Stored Procedure. I'll provide some sample code, involving a Date Parameter, for you to follow:
Expand|Select|Wrap|Line Numbers
  1. Dim cnn As ADODB.Connection
  2. Dim cmd As ADODB.Command
  3. Dim prm As ADODB.Parameter
  4.  
  5. Set cnn = CurrentProject.Connection
  6. Set cmd = New ADODB.Command
  7.  
  8. cmd.ActiveConnection = cnn
  9.  
  10. cmd.CommandText = "<Your Procedure Name>"
  11. cmd.CommandType = adCmdStoredProc
  12.  
  13. Set prm = cmd.CreateParameter("<Parameter Name>", adDBDate, adParamInput, #<Date Value Here>#
  14.  
  15. cmd.Execute
Oct 8 '08 #2
Yesh
5
Appreciate your reply. I will try this out. Meanwhile can you please help me with Q1 too.

A security alert opens up every time I try to write in to the access database. How do I avoid that?
Oct 8 '08 #3
ADezii
8,834 Expert 8TB
Appreciate your reply. I will try this out. Meanwhile can you please help me with Q1 too.

A security alert opens up every time I try to write in to the access database. How do I avoid that?
  1. What is the specific Security Alert Warning?
  2. What do you mean by 'write in to the Access Database'?
Oct 8 '08 #4
Yesh
5
Pardon me for sounding naive.

While doing an INSERT in to the database, i get a 'Security Warning' stating -

Opening "<DB path>"
This file may not be safe if it contains code that was intended to harm your computer.
Do you want to open this file or cancel the operation?

when I click on open, the database opens and it performs the INSERT command that is in my code
Oct 9 '08 #5
ADezii
8,834 Expert 8TB
Pardon me for sounding naive.

While doing an INSERT in to the database, i get a 'Security Warning' stating -

Opening "<DB path>"
This file may not be safe if it contains code that was intended to harm your computer.
Do you want to open this file or cancel the operation?

when I click on open, the database opens and it performs the INSERT command that is in my code
Try:
  1. Tools
  2. Macro
  3. Security
  4. Security Level Tab
  5. Set to Low (Read Warning!)
Oct 9 '08 #6
Yesh
5
Thanks, that worked.

When I am deleting records form a table in access I am getting a prompt as well. Is there a way to disable it?
Oct 20 '08 #7
Yesh
5
I found out the solution. Sorry for sounding naive.

Thanks anyways

Turn confirmation messages on or off
On the Tools menu, click Options.
Click the Edit/Find tab.
Under Confirm, do one or more of the following:
To display a confirmation message when you change a record, select Record changes.

To display a confirmation message when you delete a database object, select Document deletions.

To display a confirmation message when you run an action query (Access database only), select Action queries.

Note The Record changes and Action queries options don't apply to data access pages.
Oct 20 '08 #8

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

Similar topics

3
by: Hursh | last post by:
Hi, I have written some stored procedures in SQL and these procedures return some value. I want these values to be captured by the ASP code. I am able to access the tables using ADO(...
7
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was...
8
by: CSDunn | last post by:
Hello, I have a situation in which I need to address three SQL Server 2000 Stored Procedure parameters in the OnClick event of an Option Group. The Option Group lives on an Access 2000 ADP form. ...
1
by: VBSponge | last post by:
Hi all. Need help here as I cant see whats wrong... I have a querydef in Access 2k which execs a stored proc in a SQL Server 2k db. I keep getting the following error, and cant stop it for the...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
2
by: Martin Raychev | last post by:
Hi all, I have the following problem: I have a private method that returns a SqlDataReader. For this to work I have not to close the DB connection in the above method. I do this only to
4
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...
6
by: Paul M | last post by:
Hi All, I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the IBM Stored Procedure guide (SG24-7083-00). The database calls to read and update the database work...
6
by: garyb2008 | last post by:
Hello All Ive been creating my first access project in Access 2000 and SQL Server. Its up and running now for 35 users and has been pretty much a success, though ive been stopped in my tracks...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.