Solved

How to use a SQL stored procedure to poulate and then edit a form

Posted on 2011-03-12
6
247 Views
Last Modified: 2012-05-11
I have an adp and I am trying to use a stored procedure for the record source of a form. It has a parameter and it works fine for displaying the record I want. I am not able to edit the form unless I am logged in with an account that is a memeber of db_owner. Otherwise I get "This Recordset is not updateable" when I try and type something in a text field. I have given the user account execute permissions on the sproc and also added it to the db_datawriter role. I have coded the update sproc to a button and use it to perform edits.

Is it possible to use a sproc in the manner I am attempting or maybe I need to use an unbound form and populate it using an adodb recorset?
0
Comment
Question by:AkAlan
  • 4
6 Comments
 
LVL 6

Author Comment

by:AkAlan
ID: 35118924
Just as an addition, I have populated my form using an adobd recordset and I get the functionality I need, just takes longer to develop that way.
0
 
LVL 38

Accepted Solution

by:
Aaron Tomosky earned 250 total points
ID: 35119402
I believe you must use an unbound form. However you should be able to populate it in code and update in code using a stored proc. I don't think you can bind the form for filling then unbind and use a stored proc to update if that's what you're asking.
0
 
LVL 6

Author Comment

by:AkAlan
ID: 35119841
That is exactly what I was trying to do. Do you know of a reference to why not?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 35121192
Does your SP return a Recordset? If so you can bind a form to that Recordset:

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

rst.CursorLocation = adUseClient

rst.open "EXEC Your_SP", Currentproject.Connection
Set me.Recordset = rst

However, I"m not sure how this will work given your details regarding permissions. First and foremost, you'll have to insure that a standard user has the needed permissions to use the Stored Procedure (which is generally just Execute), as well as the right permissions for any table or view that the SP uses.
0
 
LVL 6

Author Comment

by:AkAlan
ID: 35122526
Thanks all for your input.  A couple of things. The code below is how I got my form to populate with data from a stored procedure. As you can see I have to populate the form controls manually but it works. If I bind the form directly to the same sproc, I get "This Recordset is not updateable" when I try to edit any text box. I have Update code on a button so I don't really want the form to do the updating like it would if I had a query. I just want the user to be able to change the text and I handle the update myself.

As for having to give the user permission to the table, that is one reason I am using sprocs. If you grant the user, in this case the AD Role the user is in, Execute permissions, you don't have to also grant them any permissions on the table. Otherwise it would be a real hassle trying to keep your database secure. I don't ever grant permissions directly to any table, period. The other reason I use sprocs is because I also provide the same Access functionality to users who have to access the data via an asp.net web app. I like that I can reuse the sprocs.  

Bottom line I guess is if  Aaron is correct, I don't have many options. I would like to see something from Microsoft that says I can't bind a sproc to an updateable Access form. I just find it wierd that when I am logged in as an admin, I can edit the text boxes but I can't do the same for my users. I am either missing something, which is entirely possible, or this is a Microsoft glitch. I will do some more research and post back if I find anything else.

 Here is my code to populate the form:  

 
 
  Dim trID As Integer
  trID = Form_frmTrainingRequirements.TrainingRequirementID
   Dim cmd As New ADODB.Command
   Dim Rst As New ADODB.Recordset
    
    With cmd
        .ActiveConnection = CurrentProject.Connection
        .CommandType = adCmdStoredProc
        .CommandText = "spSelectHR_TrainingSyllabuses"
        .Parameters("@TrainingRequirementID") = trID
        Set Rst = .Execute
    End With

Me.txtClassroomDuration = Rst!ClassroomDuration
Me.txtCourseOutline = Rst!CourseOutline
Me.txtMaterialsRequired = Rst!MaterialsRequired
Me.txtMethodOfInstruction = Rst!MethodOfInstruction
Me.txtPreRequisites = Rst!PreRequisites
Me.txtSafetyConcerns = Rst!SafetyConcerns
Me.txtTrainingReferences = Rst!TrainingReferences
Me.txtPassCriteria = Rst!PassCriteria

Open in new window


Here is my update code:
         
   Dim cmd As New ADODB.Command
            With cmd
                .ActiveConnection = CurrentProject.Connection
                .CommandType = adCmdStoredProc
                .CommandText = "spUpdateHR_TrainingSyllabus"
                .Parameters.Refresh
                .Parameters("@TrainingRequirementID") = Form_frmTrainingRequirements.TrainingRequirementID
                .Parameters("@ClassroomDuration") = Me.txtClassroomDuration
                .Parameters("@MethodOfInstruction") = Me.txtMethodOfInstruction
                .Parameters("@PreRequisites") = Me.txtPreRequisites
                .Parameters("@TrainingReferences") = Me.txtTrainingReferences
                .Parameters("@MaterialsRequired") = Me.txtMaterialsRequired
                .Parameters("@PassCriteria") = Me.txtPassCriteria
                .Parameters("@SafetyConcerns") = Me.txtSafetyConcerns
                .Parameters("@CourseOutline") = Me.txtCourseOutline
                .Execute
            End With

Open in new window

0
 
LVL 6

Author Closing Comment

by:AkAlan
ID: 35199786
I have come to the conclusion that there are multiple solutions, both of which you have helped. I don't know which solution is best and will post back here when I find a difinitive one. Thanks for the help.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

15 Experts available now in Live!

Get 1:1 Help Now