D
Dataman
I am very new to SQL Server.
Sql server 2005 and Access 2003.
I would like to use a stored procedure or view as a recordsource for a
un-bound subform. The database will contain no linked tables.
The subform does not have to be updateable as I am only using it as a
listbox type form. I want to narrow down the records to those that start
with a selected alpha key. I might also mention that the subform fields are
not bound either.
The stored procedure is called "AlphaKeys"
SELECT @PLastName = RTRIM(@PLastName ) + '%';
SELECT PLastName + ', ' + PFirstName as
PatientName,DOB,MedicalRecNumber,PatientID
FROM dbo.tblPatients
WHERE PLastName LIKE @PLastName ;
=====================================================================================
THIS IS WHAT I HAVE SO FAR
=====================================================================================
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim intPatID As Integer
Dim ctl As Control
Dim Choice As String
Dim strChoice As String
Dim strRecordset As String
cn.Open "Provider=SQLOLEDB;data Source=DATACORP-SERVER;Initial
Catalog=MySQLServer;User Id=sa;Password=sa"
'Choice returns one of the alpha characters
Choice = Choose([OptKeys], "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
"Z", "*")
If Not IsNull(Me.OptKeys) And Not Me.OptKeys = "" Then
strChoice = Choice
'Instantiante a Command Object
Set cmd = New ADODB.Command
With cmd
.CommandText = "AlphaKeys"
.CommandType = adCmdStoredProc
.ActiveConnection = cn
'Append a parameter containing the Choice
.Parameters.Append .CreateParameter("@PLastName", adVarChar,
adParamInput, 20, strChoice)
Set rst = .Execute
End With
=====================================================================================
HERE IS WHERE THINGS GO WRONG
=====================================================================================
Set Me.sbfPatientList.Form.Recordset = rst
Me.sbfPatientList.Requery
Set rst = Nothing
Set cn = Nothing
End If
Thanks for any help
Kurt
Sql server 2005 and Access 2003.
I would like to use a stored procedure or view as a recordsource for a
un-bound subform. The database will contain no linked tables.
The subform does not have to be updateable as I am only using it as a
listbox type form. I want to narrow down the records to those that start
with a selected alpha key. I might also mention that the subform fields are
not bound either.
The stored procedure is called "AlphaKeys"
SELECT @PLastName = RTRIM(@PLastName ) + '%';
SELECT PLastName + ', ' + PFirstName as
PatientName,DOB,MedicalRecNumber,PatientID
FROM dbo.tblPatients
WHERE PLastName LIKE @PLastName ;
=====================================================================================
THIS IS WHAT I HAVE SO FAR
=====================================================================================
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim fld As ADODB.Field
Dim intPatID As Integer
Dim ctl As Control
Dim Choice As String
Dim strChoice As String
Dim strRecordset As String
cn.Open "Provider=SQLOLEDB;data Source=DATACORP-SERVER;Initial
Catalog=MySQLServer;User Id=sa;Password=sa"
'Choice returns one of the alpha characters
Choice = Choose([OptKeys], "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
"Z", "*")
If Not IsNull(Me.OptKeys) And Not Me.OptKeys = "" Then
strChoice = Choice
'Instantiante a Command Object
Set cmd = New ADODB.Command
With cmd
.CommandText = "AlphaKeys"
.CommandType = adCmdStoredProc
.ActiveConnection = cn
'Append a parameter containing the Choice
.Parameters.Append .CreateParameter("@PLastName", adVarChar,
adParamInput, 20, strChoice)
Set rst = .Execute
End With
=====================================================================================
HERE IS WHERE THINGS GO WRONG
=====================================================================================
Set Me.sbfPatientList.Form.Recordset = rst
Me.sbfPatientList.Requery
Set rst = Nothing
Set cn = Nothing
End If
Thanks for any help
Kurt