473,416 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Inserting data into Access form from SQL Stored Procedure

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.

tCetecM1CUST (SQL Table that contains the Customer Information)
tAccountingDetail (SQL Table that contains the information in the
form)
frmAccountingEntry (Access form used to enter data)
spGetCustomerInformation (Stored Procedure which returns data using
variable CUSTOMER_NUMBER entered in the Access.)

Scenario is this. Open form, Enter 'Job Number' and 'Customer Number',
form uses 'AfterUpdate' to run this...

Private Sub CUSTOMER_NUMBER_AfterUpdate()
Set gcn = Nothing
Dim sConnect As String
sConnect = "PROVIDER=SQLOLEDB.1;INTEGRATED SECURITY=SSPI;PERSIST
SECURITY INFO=FALSE;INITIAL CATALOG=x;DATA SOURCE=x"
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 = "spGetCustomerInformation"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@CUSTOMER_NUMBER", adVarChar,
adParamInput, 6, Forms!frmAccountingEntry!CUSTOMER_NUMBER.Value)
Set .ActiveConnection = gcn
End With

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open cmd, , adOpenStatic, adLockReadOnly
Set rs = cmd.Execute
If Not (rs.EOF And rs.BOF) Then
MaybeMatch = True
Else
MaybeMatch = False
End If

ExitProcedure:
On Error Resume Next
Set rs = Nothing

End Sub

This passes the variable CUSTOMER_NUMBER which is located in the
Access form to the Stored Procedure which is here..

CREATE PROCEDURE dbo.spGetCustomerInformation
(@CUSTOMER_NUMBER varchar(6))
AS
SELECT CUSTOMER_NUMBER, CUSTOMER_NAME, ADDRESS_1, ADDRESS_2,
ADDRESS_3, ADDRESS_4, SHIP_ADDRESS_1, SHIP_ADDRESS_2, SHIP_ADDRESS_3,
SHIP_ADDRESS_4
FROM dbo.tCetecM1CUST
WHERE (CUSTOMER_NUMBER = @CUSTOMER_NUMBER)

Which then does nothing as far as returning the data to the current
form. I can run the stored procedure in Access and a Message Box will
come up prompting me to enter the 'CUSTOMER_NUMBER'. If the number
entered matches a record, then the record is displayed.

So, what am I missing here? I feel like there must be another piece of
code that puts the data back into the current record or form.

Thanks to anyone out there who has a suggestion.

-Josh
Nov 12 '05 #1
2 11661
Josh Strickland wrote:
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.

tCetecM1CUST (SQL Table that contains the Customer Information)
tAccountingDetail (SQL Table that contains the information in the
form)
frmAccountingEntry (Access form used to enter data)
spGetCustomerInformation (Stored Procedure which returns data using
variable CUSTOMER_NUMBER entered in the Access.)

Scenario is this. Open form, Enter 'Job Number' and 'Customer Number',
form uses 'AfterUpdate' to run this...

Private Sub CUSTOMER_NUMBER_AfterUpdate()
Set gcn = Nothing
Dim sConnect As String
sConnect = "PROVIDER=SQLOLEDB.1;INTEGRATED SECURITY=SSPI;PERSIST
SECURITY INFO=FALSE;INITIAL CATALOG=x;DATA SOURCE=x"
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 = "spGetCustomerInformation"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@CUSTOMER_NUMBER", adVarChar,
adParamInput, 6, Forms!frmAccountingEntry!CUSTOMER_NUMBER.Value)
Set .ActiveConnection = gcn
End With

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open cmd, , adOpenStatic, adLockReadOnly
Set rs = cmd.Execute
If Not (rs.EOF And rs.BOF) Then
MaybeMatch = True
Else
MaybeMatch = False
End If

ExitProcedure:
On Error Resume Next
Set rs = Nothing

End Sub

This passes the variable CUSTOMER_NUMBER which is located in the
Access form to the Stored Procedure which is here..

CREATE PROCEDURE dbo.spGetCustomerInformation
(@CUSTOMER_NUMBER varchar(6))
AS
SELECT CUSTOMER_NUMBER, CUSTOMER_NAME, ADDRESS_1, ADDRESS_2,
ADDRESS_3, ADDRESS_4, SHIP_ADDRESS_1, SHIP_ADDRESS_2, SHIP_ADDRESS_3,
SHIP_ADDRESS_4
FROM dbo.tCetecM1CUST
WHERE (CUSTOMER_NUMBER = @CUSTOMER_NUMBER)

Which then does nothing as far as returning the data to the current
form. I can run the stored procedure in Access and a Message Box will
come up prompting me to enter the 'CUSTOMER_NUMBER'. If the number
entered matches a record, then the record is displayed.

So, what am I missing here? I feel like there must be another piece of
code that puts the data back into the current record or form.

Thanks to anyone out there who has a suggestion.

-Josh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I don't work w/ ADO - mainly 'cuz I can get the info I need in DAO in
about 5 lines of code where ADO requires 10-15 lines. Anyway, . . .
I'll assume you're using Access 2000, or Access XP; can't you set the
form's Recordset to the recordset returned by the stored procedure?
E.g.:

Set Me.Recordset = rs

Here's some code from Acc XP Help on "Recordset Property."

Global rstSuppliers As ADODB.Recordset
Sub MakeRW()
DoCmd.OpenForm "Suppliers"
Set rstSuppliers = New ADODB.Recordset
rstSuppliers.CursorLocation = adUseClient
rstSuppliers.Open "Select * From Suppliers", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic

' See - this line sets the form's recordset...:::mgf
Set Forms("Suppliers").Recordset = rstSuppliers

' Not sure why this line is needed, but it works...:::mgf
Forms("Suppliers").UniqueTable = "Suppliers"

End Sub

HTH,
- --
MGFoster:::mgf
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP4dfQYechKqOuFEgEQKQGwCdHA2DZvZUlq7C82CXfTdxry snsNwAn2vd
AQO2Wudr+5FPVuV37Fangt8/
=Rb4i
-----END PGP SIGNATURE-----

Nov 12 '05 #2
"Josh Strickland" <js*********@btcelectronics.com> wrote in message
news:ad**************************@posting.google.c om...
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.

tCetecM1CUST (SQL Table that contains the Customer Information)
tAccountingDetail (SQL Table that contains the information in the
form)
frmAccountingEntry (Access form used to enter data)
spGetCustomerInformation (Stored Procedure which returns data using
variable CUSTOMER_NUMBER entered in the Access.)

Scenario is this. Open form, Enter 'Job Number' and 'Customer Number',
form uses 'AfterUpdate' to run this...

Private Sub CUSTOMER_NUMBER_AfterUpdate()
Set gcn = Nothing
Dim sConnect As String
sConnect = "PROVIDER=SQLOLEDB.1;INTEGRATED SECURITY=SSPI;PERSIST
SECURITY INFO=FALSE;INITIAL CATALOG=x;DATA SOURCE=x"
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 = "spGetCustomerInformation"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@CUSTOMER_NUMBER", adVarChar,
adParamInput, 6, Forms!frmAccountingEntry!CUSTOMER_NUMBER.Value)
Set .ActiveConnection = gcn
End With

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open cmd, , adOpenStatic, adLockReadOnly
Set rs = cmd.Execute
If Not (rs.EOF And rs.BOF) Then
MaybeMatch = True
Else
MaybeMatch = False
End If

ExitProcedure:
On Error Resume Next
Set rs = Nothing

End Sub

This passes the variable CUSTOMER_NUMBER which is located in the
Access form to the Stored Procedure which is here..

CREATE PROCEDURE dbo.spGetCustomerInformation
(@CUSTOMER_NUMBER varchar(6))
AS
SELECT CUSTOMER_NUMBER, CUSTOMER_NAME, ADDRESS_1, ADDRESS_2,
ADDRESS_3, ADDRESS_4, SHIP_ADDRESS_1, SHIP_ADDRESS_2, SHIP_ADDRESS_3,
SHIP_ADDRESS_4
FROM dbo.tCetecM1CUST
WHERE (CUSTOMER_NUMBER = @CUSTOMER_NUMBER)

Which then does nothing as far as returning the data to the current
form. I can run the stored procedure in Access and a Message Box will
come up prompting me to enter the 'CUSTOMER_NUMBER'. If the number
entered matches a record, then the record is displayed.

So, what am I missing here? I feel like there must be another piece of
code that puts the data back into the current record or form.

Thanks to anyone out there who has a suggestion.

-Josh
It's a bit hard to see exactly where it's going wrong but I would check here
first:
rs.Open cmd, , adOpenStatic, adLockReadOnly
Set rs = cmd.Execute


You've already set rs, then you open it, then you re-set it? Why?

As you step through your code, can you check this is giving the value you
expect, before passing it to the stored procedure:

Forms!frmAccountingEntry!CUSTOMER_NUMBER.Value

Also what about some more general error handling for the sub and why is
there no dim statement for MaybeMatch and why does it not follow a naming
convention.
Just some ideas

Fletcher
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
0
by: Sal | last post by:
I just had a C# conversion project thrown at me, and must bind several text boxes on a form to different columns from a table. We have to use stored procedures that are called through data layer...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: hooterbite | last post by:
I have a simple form. I would like to insert the values from the form into a SQL table. What is the best way to do it? I assume that using a stored procedure is preferable to using the...
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
4
by: Dia | last post by:
Hi there, I struggle to get this going i would like to insert data into 2 tmp tables in a view. If i run the code on it's own it works perfectly until i want to create a view it complains...
6
by: binky | last post by:
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...
2
by: cluce | last post by:
I am trying to read a csv file with user info (username, password, email, address, city, zip, state, etc.) I am inserting the username, password, email into the aspnet_memberhsip table using the...
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.