Link to home
Create AccountLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

MS Access Linked Tables

I have a MDB Database that uses linked tables to SQL Server and an ODBC COnnection

On the SQL Server, I want to access some stored procedures in the same database.

I want to establish a  connection so I can use something like the code below

How do I set cmd.ActiveConnection  to look at the itTasks database on the sqlserverDEV\DEV server and instance?

Private Sub FillAssignments()
    Dim cmd As New ADODB.Command
    cmd.ActiveConnection = Conn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "usp_EmployeeAssignments"
    cmd.Parameters("@EmployeeNumber") = Nz(Me.Employee_Number, 0)
    Set Me.Assignment_Number.Recordset = cmd.Execute()
End Sub
Avatar of chaau
chaau
Flag of Australia image

I think this article should help you.
Basically, you need to set Me.Assignment_Number.Recordset.Options = dbSQLPassThrough so that MS Access does not validate the statement and used the recordset from the stored procedures for your data set
Check this. Added to and modified  your current code:

Private Sub FillAssignments()
	Dim cmd As New ADODB.Command
	Dim inParasm As Variant
	Dim outParam As Variant 'added---
	Dim param As ADODB.Parameter 'added---
	Set cmd = New Command 'added ---
	cmd.ActiveConnection = CurrentProject.Connection 'modified ---
	cmd.CommandType = adCmdStoredProc
	cmd.CommandText = "usp_EmployeeAssignments"
	cmd.parameters.Append cmd.CreateParameters("inParam",adBSTR,adParameterInput) ' added---
	cmd.parameters.Append cmd.CreateParameters("OutParam",adBSTR,adParameterOutput) ' added---
	cmd.Parameters("inParam") = Nz(Me.Employee_Number, 0)'modified---
	cmd.Execute 'added---
	Set Me.Assignment_Number.Recordset = cmd.Parameters("outParam")'modified ---
	Set cmd= Nothing 'added---
End Sub 

Open in new window

Avatar of Larry Brister

ASKER

hnasf

Your instructions appear incomplete.

chaa
That link was way too generic.

Guys...seems to me I need to run a pass through query...I just can't remember how
"Your instructions appear incomplete."
I followed your example assuming your using access data project adp
I added few lines, modified others in your code.




If using an access database mdb, or accdb then you can use a  passthrough query.
I'll give it a try sometime later if problem not solved.
hnasr
Looking at my comments they appear impolite.
Not my intention at all and my apologies.

What I meant is that it looks like I need to modify a stored procedure to have an output?

I'm trying to get a multiple row - multiple column recordset back in order to populate a datasheet view form
ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks.
This thing was making me crazy
Welcome!