468,110 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

Stored procedure to fill listbox, using 'exec'

Hey,

Coming back to a piece of work I did a while back, which used a stored
procedure to populate a list box. The SP takes a single parameter, and
I think this is the reasoning for using 'exec' in the row source (I
assume you need this for parameters?)

The problem is this only works when I access the form.. If I do it from
someone else's computer they get a blank listbox. They have appropriate
permissions for the stored procedure, so is the 'exec' getting in the way?

Can I use a parameterised sp in a row source for a listbox without using
exec? or is there a way of sorting it that the user can use the stored
procedure? (there's no error messages to say there's no access)

The stored procedure was created using my login, not dbo (if that makes
a difference)

Thanks for any help you can give!
Chris
Nov 13 '05 #1
2 3541
Not Me <No***********@here.com> wrote in
news:ci**********@ucsnew1.ncl.ac.uk:
Hey,

Coming back to a piece of work I did a while back, which used a stored
procedure to populate a list box. The SP takes a single parameter,
and I think this is the reasoning for using 'exec' in the row source
(I assume you need this for parameters?)

The problem is this only works when I access the form.. If I do it
from someone else's computer they get a blank listbox. They have
appropriate permissions for the stored procedure, so is the 'exec'
getting in the way?

Can I use a parameterised sp in a row source for a listbox without
using exec? or is there a way of sorting it that the user can use the
stored procedure? (there's no error messages to say there's no access)

The stored procedure was created using my login, not dbo (if that
makes a difference)

Thanks for any help you can give!
Chris


Recently I have resorted to using a string as follows:

***************************************
lstTeachers.RowSourceType is Value List.

Form_open Code is:

Private Sub Form_Open(Cancel As Integer)
Dim r As ADODB.Recordset
Dim TSQL As String
If SysCmd(acSysCmdGetObjectState, acForm, "frmAssignTeachers") And
acObjStateOpen = acObjStateOpen Then
TSQL = "SELECT 0 AS fldTeacherID, NULL AS fldTeacherName" _
& vbNewLine & "UNION" & vbNewLine & _
"SELECT fldTeacherID, fldTeacherName FROM tblTeachers
WHERE fldSchoolID = " & Form_frmAssignTeachers.txtSchoolID.Value & "
ORDER BY fldTeacherName"
With Me
.lstTeachers.RowSource = CurrentProject.Connection.Execute
(TSQL).GetString(, , ",", ",")
.InsideHeight = Form_frmAssignTeachers.InsideHeight
End With
PlaceForm Me
End If
End Sub
*******

In the code there are procedures extraneous to the question at hand, of
course. As ever, line breaks introduced by news clients can make code
unusable without editing.

There does not seem to be any noticeable time penalty for this way of
doing things. As far as I know, it is the only way to use the equivalent
of parameterized stored procedures with Application Role MS-SQL
permissions and ADPs.


Nov 13 '05 #2
Lyle Fairfield wrote:
Not Me <No***********@here.com> wrote in
news:ci**********@ucsnew1.ncl.ac.uk:
Hey, <snip>Can I use a parameterised sp in a row source for a listbox without
using exec? or is there a way of sorting it that the user can use the
stored procedure? (there's no error messages to say there's no access)
Recently I have resorted to using a string as follows:

***************************************
lstTeachers.RowSourceType is Value List.

Form_open Code is:

Private Sub Form_Open(Cancel As Integer)
Dim r As ADODB.Recordset
Dim TSQL As String
If SysCmd(acSysCmdGetObjectState, acForm, "frmAssignTeachers") And
acObjStateOpen = acObjStateOpen Then
TSQL = "SELECT 0 AS fldTeacherID, NULL AS fldTeacherName" _
& vbNewLine & "UNION" & vbNewLine & _
"SELECT fldTeacherID, fldTeacherName FROM tblTeachers
WHERE fldSchoolID = " & Form_frmAssignTeachers.txtSchoolID.Value & "
ORDER BY fldTeacherName"
With Me
.lstTeachers.RowSource = CurrentProject.Connection.Execute
(TSQL).GetString(, , ",", ",")
.InsideHeight = Form_frmAssignTeachers.InsideHeight
End With
PlaceForm Me
End If
End Sub
*******
There does not seem to be any noticeable time penalty for this way of
doing things. As far as I know, it is the only way to use the equivalent
of parameterized stored procedures with Application Role MS-SQL
permissions and ADPs.


Thanks for that, I will look into it as it should help my understanding
of this better, though in the meantime I seem to have fixed the problem
by changing the ownership of the procedures to 'dbo'.

Cheers,
Chris
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by pompeyoc | last post: by
reply views Thread by SOI_0152 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.