Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access ADP recordsource to SQL server

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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