Hi folks, I'm just learning how to use MS Access as a front end for SQL Server, and have a question:
I have a stored procedure that returns a set of records from a SQL Server and loads it into a form in my Access application. This works as intended, but I'm having trouble trying to figure out how to modify records on the form... whenever I try i get the error that says youc an't modify this data because its based on an expression.
i'm just learning stored procedures in access so i was wondering if anybody could help. the code that populates the form is below.
Basically I'm wondering if I can have the application automatically update data without having to create a 2nd procedure to push changes back to the server. - Set gcn = Nothing
-
Dim sConnect As String
-
sConnect = "Driver={SQL Server};Server=XXXX;Database=XXXXX;Trusted_Connect ion=Yes;"
-
-
Set gcn = New ADODB.Connection
-
gcn.CursorLocation = adUseClient
-
gcn.Open sConnect
-
-
'On Error GoTo ExitProcedure
-
Dim rs As ADODB.Recordset
-
Set rs = New ADODB.Recordset
-
'Call doConnect
-
-
Dim cmd As ADODB.Command
-
Set cmd = New ADODB.Command
-
-
With cmd
-
.CommandText = "my_procedure"
-
.CommandType = adCmdStoredProc
-
.Parameters.Append .CreateParameter("@parm1", adChar, adParamInput, 15, Me.cbxData_Set)
-
Set .ActiveConnection = gcn
-
End With
-
-
Set rs = New ADODB.Recordset
-
rs.CursorLocation = adUseServer
-
rs.Open cmd, , adOpenStatic, adLockPessimistic
-
-
Set rs = cmd.Execute
-
-
Set Me.Form.Recordset = rs
6 6586
Hi folks, I'm just learning how to use MS Access as a front end for SQL Server, and have a question:
I have a stored procedure that returns a set of records from a SQL Server and loads it into a form in my Access application. This works as intended, but I'm having trouble trying to figure out how to modify records on the form... whenever I try i get the error that says youc an't modify this data because its based on an expression.
i'm just learning stored procedures in access so i was wondering if anybody could help. the code that populates the form is below.
Basically I'm wondering if I can have the application automatically update data without having to create a 2nd procedure to push changes back to the server. - Set gcn = Nothing
-
Dim sConnect As String
-
sConnect = "Driver={SQL Server};Server=XXXX;Database=XXXXX;Trusted_Connect ion=Yes;"
-
-
Set gcn = New ADODB.Connection
-
gcn.CursorLocation = adUseClient
-
gcn.Open sConnect
-
-
'On Error GoTo ExitProcedure
-
Dim rs As ADODB.Recordset
-
Set rs = New ADODB.Recordset
-
'Call doConnect
-
-
Dim cmd As ADODB.Command
-
Set cmd = New ADODB.Command
-
-
With cmd
-
.CommandText = "my_procedure"
-
.CommandType = adCmdStoredProc
-
.Parameters.Append .CreateParameter("@parm1", adChar, adParamInput, 15, Me.cbxData_Set)
-
Set .ActiveConnection = gcn
-
End With
-
-
Set rs = New ADODB.Recordset
-
rs.CursorLocation = adUseServer
-
rs.Open cmd, , adOpenStatic, adLockPessimistic
-
-
Set rs = cmd.Execute
-
-
Set Me.Form.Recordset = rs
Can you post the contents of "my_procedure"?
The stored procedure is below. It's a simple SQL query that uses parameters passed from the application. - IF OBJECT_ID('my_procedure') IS NOT NULL
-
DROP PROCEDURE my_procedure
-
GO
-
-
CREATE PROCEDURE dbo.my_procedure
-
(@p_cPrcsNm CHAR (15)
-
,@p_cErrMsg CHAR (75)
-
,@p_vButton int
-
,@p_vAssgnCd VARCHAR (3)
-
,@p_vRouteCd VARCHAR (4)
-
,@p_vStatusCd CHAR (10)
-
)
-
AS
-
-
BEGIN
-
SELECT a.*, b.* FROM dbo.cs_br AS a
-
LEFT JOIN dbo.cs_tr AS b
-
ON a.cv_id = b.cv_id
-
WHERE a.prcs_nm = @p_cPrcsNm
-
and (@p_cErrMsg IS NULL OR a.err_msg = @p_cErrMsg)
-
and (@p_vStatusCd IS NULL OR a.status_cd = @p_vStatusCd)
-
and (@p_vAssgnCd IS NULL OR LTRIM(RTRIM (b.assgn_cd)) = @p_vAssgnCd)
-
and (@p_vRouteCd IS NULL OR b.route_cd = @p_vRouteCD)
-
END
-
-
GO
/bump for anybody that might be able to help :)
/bump for anybody that might be able to help :)
Hello binky, I am by no means an expert on Stored Procedures, but here are a few of my initial observations. I hope that they will point you in the right direction: - The Recordset that is dynamically assigned to your Form was opened via a Static Cursor Type, try a Keyset Cursor instead as in:
- rs.Open cmd, , adOpenKeyset, adLockPessimistic
- my_procedure accepts 6 Input Parameters, but I see only 1 being appended to the Command Objects Parameters Collection:
- .Parameters.Append .CreateParameter("@parm1", adChar, adParamInput, 15, Me.cbxData_Set)
- You stated that Input Parameters are being passed from the Application, but how?
- The SQL Statement as defined in your Stored Procedure, involves a Left Outer Join. Perhaps this could be the reason why the data is not Updateable? Try a Standard Inner Join and see if the results are the same.
- Fields based on Expressions are, in fact, not Updateable but I see no indication of this.
- Fields on Forms based on a 1 to Many Join from a Stored Procedure are Updateable if they are in the most-many Table and this Table has been specified as the Unique Table for the Form. Is this your case?
- You are using Integrated Security within your Connection String (Trusted_Connection= Yes). Do you have the required Permissions on the Server?
- When you use the Execute() Method of a Command Object with Parameters, the resulting Recordset is Read Only. Try replacing these 2 lines:
- rs.Open cmd, , adOpenStatic, adLockPessimistic
-
Set rst = cmd.Execute
with this single line: - rs.Open cmd, , adOpenKeyset, adLockOptimistic, adCmdStoredProcedure
- As far as I know, you shouldn't need a 2nd Procedure to 'push' data back to the Server.
- Try each point in turn and see what happens. Keep me informed as to your progress, since you peaked my interest with this one.
Thanks for the reply :)
I might have found a workaround, and that's by migrating everything from a MDB project into an ADP project. Then I can use my existing procedure as the recordsource on a form and Access apparently handles the edits with all the appropriate record locks automatically.
But I will also try your suggestions, and see what works best :)
Thanks for the reply :)
I might have found a workaround, and that's by migrating everything from a MDB project into an ADP project. Then I can use my existing procedure as the recordsource on a form and Access apparently handles the edits with all the appropriate record locks automatically.
But I will also try your suggestions, and see what works best :)
Hi folks, I'm just learning how to use MS Access as a front end for SQL Server, and have a question:
Sorry binky, but I was under the impression that you were using an Access Project.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Roy Adams |
last post by:
Hi everyone
I'm trying to build a shopping cart app using a db the part I'm stuck
on is the fact that, if someone adds a product that they have
previously added to the cart.
I've got it set up to...
|
by: Jarrod Morrison |
last post by:
Hi All
Im generally a vb programmer and am used to referencing multiple records
returned from a query performed on an sql database and im trying to move
some functions of my software into sql...
|
by: Ryan.Chowdhury |
last post by:
This is a general question regarding the use of view and stored
procedures. I'm fairly new to databases and SQL.
I've created a SQL database using an Access Data Project ("ADP") and
I'm...
|
by: M Wells |
last post by:
Hi All,
I'm trying to track down a mysterious problem we're experiencing in
which updates and inserts to tables in our mssql2k server appear to be
'disappearing.'
To explain our situation:
...
|
by: Josh Strickland |
last post by:
I am attempting to create an Access database which uses forms to enter
data. The issue I am having is returning the query results from the
Stored Procedure back in to the Access Form.
...
|
by: Wojciech Wendrychowicz |
last post by:
Hello to All,
I'm trying to retrieve records from AS/400 in an VBA application.
So, I've made an RPG program, then a stored procedure wchich calls that RPG
program, and finally some VBA code to...
|
by: Jeff |
last post by:
For years I have been using VBA extensively for updating data to tables
after processing. By this I mean if I had to do some intensive processing
that resulted in data in temp tables, I would have...
|
by: lemes_m |
last post by:
Hi All!
I have very big problem and I can't continue my Work on my project
until i solve it.
Here is the situation:
TblCalculations
FldCalcId FldArticle FldQuantity FldPrice ...
|
by: TC |
last post by:
I need an automated procedure to copy data from an Access table to a
SQL Server table. Speed is important. What is the recommended
technique?
I can export the data from Access, copy it via FTP,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |