Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access ADP recordsource to SQL server

Posted on 2013-05-10
2
Medium Priority
?
885 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 1620 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

927 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