?
Solved

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

Posted on 2011-03-12
6
Medium Priority
?
292 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
[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
  • 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 39

Accepted Solution

by:
Aaron Tomosky earned 1000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

752 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