Solved

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

Posted on 2011-03-12
6
274 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 39

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

840 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