Solved

Access ADP recordsource to SQL server

Posted on 2013-05-10
2
855 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Viewers will learn how the fundamental information of how to create a table.

751 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