Solved

Access ADP recordsource to SQL server

Posted on 2013-05-10
2
836 Views
Last Modified: 2013-05-11
I created an access .adp database and have it linked to SQL server.  I have a stored procedure in SQL called spSelectMyAction which has a variable @GetAction.  I would like to pass a variable from an access form (Form_employee.cboaction) to SQL, run the stored procedure and have it populate the recordsource on a form.  

In the most basic form which doesn't work, I want this:

Me.recordsouce = EXEC spSelectMyAction "cboaction"

Anyone know the correct syntax?
0
Comment
Question by:marku24
2 Comments
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 405 total points
ID: 39157715
Hi,

there are different possibilities for this problem:

First you can set the name of the SP directly as RecordSource. This can be done by choosing the name of the SP in the RecordSource combobox of the form. Then you can use the second property to set the SP's parameters which is only available in ADP forms: "Input Parameter". Here you can use Access syntax to fill in the parameters, for example using a variable coming from another form's control names "MyText":

@MyParameterName = Nz(Forms!MyOtherForm!MyText)

Open in new window


You can also specify the parameter type with this property:

@MyParameterName nvarchar(50) = Nz(Forms!MyOtherForm!MyText)

Open in new window


Or with using the OpenArgs:

@MyParameterName nvarchar(50) = Nz(Form.OpenArgs)

Open in new window



Second method is to use VBA to fill the RecordSource:

Me.RecordSouce = "EXEC spSelectMyAction @MyParameterName = '" & Nz(Me.OpenArgs) & "'"

Open in new window


In case where you filled the action by using the "OpenArgs" parameter in the DoCmd.OpenForm command.


Third method is to use the Recordset property of the form but this one is a little bit tricky: You must open a recordset and then assign the opened recordset to the form's recordset property. Works, is also updatable (if you made the recordset updatable before opening it) but has the disadvantage that Access sometimes cannot requery the form correctly if not all parameters of the SP are part of the initial EXEC command. (I must use this kind of assignment currently in my project and simply disabled any requery like F5 key and created an own requery by reloading the recordset again if someone hits F5).

Cheers,

Christian
0
 

Author Closing Comment

by:marku24
ID: 39158818
this was an amazing answer.  So detailed and easy to follow.  Thank you
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
t-sql Joining Issue 10 40
is Microsoft Access going to Die? 9 50
SQL Query assistance 16 26
Modify report 8 8
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I have a large data set and a SSIS package. How can I load this file in multi threading?
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question