Solved

Access ADP recordsource to SQL server

Posted on 2013-05-10
2
821 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now