PC Review


Reply
Thread Tools Rate Thread

Access ADP Form and Stored Procedure as RecordSource Options

 
 
chrise
Guest
Posts: n/a
 
      29th Jul 2009
This may be common knowledge but I could not find any posts. My ADP
form allows the user to input search criteria into textboxes,
checkboxes, and listboxes in the Form Header and the results are
displayed in the detail section of the form. First, in the form
properties, I set the form RecordSource to one Stored Procedure that
would return the last 50 records created when the form is first
opened
with no Input Parameters. That worked. I would change the
Me.RecordSource property, to a second Stored Procedure, in code when
the Search button was clicked and include all the Input Parameters
from the search criteria the user would input. This failed every
time.
What I realized is you can't change the RecordSource from one Stored
Procedure to a second Stored Procedure if the Input Parameters do not
match exactly. My solution was to Remove the RecordSource and Input
Parameters from the Form Properties and assign these in the Form Open
event. I use the same Stored Procedure to open the form and the
search
button function. When the form opens instead of displaying the last
50
records, I display all records created in the last 60 days.

When you assign a Stored Procedure with Input Parameters as the
RecordSource in code, you must set up the Me.InputParameters first
then assign the Me.RecordSource second. I also tried concatenating a
string to assign as the InputParameter but that didn’t work. This is
how I got it to work


Me.InputParameters = “@Param1=’” & strParam1 & _
“,@Param2=’” & strParam2 & “’,@Param3=’” & _
strParam3 & “’”

 
Reply With Quote
 
 
 
 
Bob
Guest
Posts: n/a
 
      30th Jul 2009
One option is to have your SP look at a param to tell it what query
to use... Then just change the Form.Inputparameters in the combo.OnChange
Event.

something like
Create
Proc YourStoredProc
@whatQuery int
, @param1 ...
, @param2
as

if @whatQuery = 1
Begin
Select ..
From..
--no params
End
if @whatQuery = 2
Begin
Select ..
From..
where something = @param1 and somethingelse = @param2
End

hth,
...bob

"chrise" <(E-Mail Removed)> wrote in message
news:4b313059-d4ae-4ab9-9391-(E-Mail Removed)...
This may be common knowledge but I could not find any posts. My ADP
form allows the user to input search criteria into textboxes,
checkboxes, and listboxes in the Form Header and the results are
displayed in the detail section of the form. First, in the form
properties, I set the form RecordSource to one Stored Procedure that
would return the last 50 records created when the form is first
opened
with no Input Parameters. That worked. I would change the
Me.RecordSource property, to a second Stored Procedure, in code when
the Search button was clicked and include all the Input Parameters
from the search criteria the user would input. This failed every
time.
What I realized is you can't change the RecordSource from one Stored
Procedure to a second Stored Procedure if the Input Parameters do not
match exactly. My solution was to Remove the RecordSource and Input
Parameters from the Form Properties and assign these in the Form Open
event. I use the same Stored Procedure to open the form and the
search
button function. When the form opens instead of displaying the last
50
records, I display all records created in the last 60 days.

When you assign a Stored Procedure with Input Parameters as the
RecordSource in code, you must set up the Me.InputParameters first
then assign the Me.RecordSource second. I also tried concatenating a
string to assign as the InputParameter but that didn’t work. This is
how I got it to work


Me.InputParameters = “@Param1=’” & strParam1 & _
“,@Param2=’” & strParam2 & “’,@Param3=’” & _
strParam3 & “’”

 
Reply With Quote
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      30th Jul 2009
A second possibility would be to build a sql string beginning with "EXEC "
then followed with the name of the procedure and the required parameters and
use this string a the record source. I've always used EXEC at the beginning
to make an explicit call in T-SQL to the stored procedure but maybe it's not
really necessary.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Email: sylvain2009 sylvainlafontaine com (fill the blanks, no spam please)
Independent consultant and remote programming for Access and SQL-Server
(French)


"Bob" <(E-Mail Removed)> wrote in message
news:F75FEE82-FA12-4636-A922-(E-Mail Removed)...
> One option is to have your SP look at a param to tell it what query
> to use... Then just change the Form.Inputparameters in the combo.OnChange
> Event.
>
> something like
> Create
> Proc YourStoredProc
> @whatQuery int
> , @param1 ...
> , @param2
> as
>
> if @whatQuery = 1
> Begin
> Select ..
> From..
> --no params
> End
> if @whatQuery = 2
> Begin
> Select ..
> From..
> where something = @param1 and somethingelse = @param2
> End
>
> hth,
> ..bob
>
> "chrise" <(E-Mail Removed)> wrote in message
> news:4b313059-d4ae-4ab9-9391-(E-Mail Removed)...
> This may be common knowledge but I could not find any posts. My ADP
> form allows the user to input search criteria into textboxes,
> checkboxes, and listboxes in the Form Header and the results are
> displayed in the detail section of the form. First, in the form
> properties, I set the form RecordSource to one Stored Procedure that
> would return the last 50 records created when the form is first
> opened
> with no Input Parameters. That worked. I would change the
> Me.RecordSource property, to a second Stored Procedure, in code when
> the Search button was clicked and include all the Input Parameters
> from the search criteria the user would input. This failed every
> time.
> What I realized is you can't change the RecordSource from one Stored
> Procedure to a second Stored Procedure if the Input Parameters do not
> match exactly. My solution was to Remove the RecordSource and Input
> Parameters from the Form Properties and assign these in the Form Open
> event. I use the same Stored Procedure to open the form and the
> search
> button function. When the form opens instead of displaying the last
> 50
> records, I display all records created in the last 60 days.
>
> When you assign a Stored Procedure with Input Parameters as the
> RecordSource in code, you must set up the Me.InputParameters first
> then assign the Me.RecordSource second. I also tried concatenating a
> string to assign as the InputParameter but that didn’t work. This is
> how I got it to work
>
>
> Me.InputParameters = “@Param1=’” & strParam1 & _
> “,@Param2=’” & strParam2 & “’,@Param3=’” & _
> strParam3 & “’”
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access ADP Form and Stored Procedure as RecordSource chrise Microsoft Access Queries 0 29th Jul 2009 07:21 PM
stored procedure as RecordSource Wm Microsoft Access Reports 1 4th May 2005 05:44 PM
Stored Procedure as RecordSource does not work in Access 2002 Brad Naugle Microsoft Access ADP SQL Server 0 3rd Jun 2004 02:54 PM
Stored procedure is recordsource for form and should return a parameter. How? furkat Microsoft Access ADP SQL Server 2 26th May 2004 07:11 PM
form parameter using stored procedure in the recordsource property udong mawanay Microsoft Access Forms 0 31st Oct 2003 07:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.