DataBase - Sql Server and Un-Bound Forms

Asked By Dataman
30-Sep-09 04:12 PM
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",

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
ADODB.Connection
(1)
ADODB.Command
(1)
SQL Server
(1)
ADODB.Recordset
(1)
ADODB.Field
(1)
Access 2003
(1)
MySQLServer
(1)
ADODB
(1)
  Banana replied...
30-Sep-09 04:40 PM
Strictly speaking, you are not working with unbound forms. You're in fact
binding a ADO recordset to form which is very legitimate thing to do and
if the conditions are met, it can be updatable as well so if you really
do not want it to be updatable, then you need to set the form/query
accordingly.

That said, I do not see cursors type/location being specified. The safest
setting is to coerece the cursor to client-side static cursor. With SQL
Server, you can use server-side dynamic, if I remember it right. Also,
you normally would hold the recordset until the form's close rather than
disposing it in the same event handler that created it.

Google for a KB article about "binding ADO recordset to MS Access form"
to get a good explanation and code samples.

HTH.
  Dataman replied...
01-Oct-09 11:31 AM
Thanks for the heads up.

Kurt
Create New Account
help
Might be outgrowing Access but daunted by SQL Server DataBase I am close to completing the consolidation of various small Access databases and a spent the last 10 hours downloading, installing and trying to get my head around Microsoft SQL Server 2008 Express and how it might help me out. It all started when I came encouraging article on keeping your Access database as your front end application and linking to SQL Server database tables. I am finding it MUCH more complicated than I had hoped. Can anyone be happy to use my quite powerful workstation at the office as some kind of server. You may have guessed by now that I am no IT guru by any stretch so please bare this in mind with any suggestions. Access Discussions SQL Server Migration Assistant (1) SQL Server 2005 (1) SQL Server 2008 (1) SQL Server (1
SQL qui ne fonctionne pas en VBA DataBase Bonjour, En VBA je construit une chaine contenant du SQL. Le recordset ne renvoie rien. Par contre si je colle la chaine dans l' = E9diteur E8res sont des contr = F4les du formulaire) Dim sSql As String Dim Rst As New ADODB.Recordset Dim CN As ADODB.Connection Set CN = 3D CurrentProject.Connection Dim j1 As Integer, j2 As Integer Dim I As ORDER BY Tbl_D_Implementations.Cnl_Id, DatePart('w', [quot_date], 2, 2);" Rst.Open sSql, CN, adOpenStatic . . . le SQL : SELECT DatePart('w', [quot_date], 2, 2) AS J, Count(DatePart('w', [quot_date], 2, 2)) AS 10154 82428 3 6 147 3078 90267 3 7 150 2695 91042 3 Access Discussions ADODB.Connection (1) SQL Server (1) INNER JOIN (1) Module (1) ADODB (1) Date (1) VBA
0 Data S (1) CreateObject Excel.Application sSource CurrentProject.Path 1995.xls With (1) New ADODB.Recordset OutTable.ActiveConnection (1) New ADODB.Recordset InTable.ActiveConnection (1) End With xl.Application.Quit End Function uhmmm (1) ADO Dicevo Con codice seguente: (preso da un libro o'reilly ISBN 9780596101220) Sub Example7_18A() Dim InTable As ADODB.Recordset Dim OutTable As ADODB.Recordset Dim fld As ADODB.Field Set InTable = New ADODB.Recordset InTable.ActiveConnection = "Provider = Microsoft.Jet
asText As String) As Long 'ID suchen Dim lngID As Long Dim CONN As New ADODB.Connection Set CONN = CurrentProject.Connection Dim DBS As ADODB.Recordset Set DBS = New ADODB.Recordset DBS.Open "SELECT ID FROM Art_Kat WHERE Bezeichnung = '" & asText & "'", CONN, adOpenKeyset, adLockOptimistic If DBS.RecordCount auf den einzelnen Clients ist nicht fix!) anzugeben? Danke schon mal mfg Christian Access Discussions ADODB.Connection (1) Oracle (1) Office (1) ADODB (1) VBA (1) DB (1) Application (1) MoveNext (1
tmptbl_fg_komponenten_anforderung].[welches_lastenheft] And 2) WHERE (((tmptbl_fg_komponenten_anforderung.kriteriums_rangfolge) = 3)); Damit ist das AND der Fehler im SQL-Statement. Ersetzen muss ich das durch? Gr?sse Alex. Access Discussions ADODB.Connection (1) ADODB.Command (1) Error (1) SQL Anweisungen (1) ADODB (1) VBA (1) Application (1) Bits (1) Hallo! Alexander Bierig schrieb: [. . .] . . . mehrere binary and") ersetzen. Da BAND von DAO (ANSI89) allerdings nicht erkannt wird, musst du diese SQL-Anweisung ?ber ADODB ausf?hren. Falls du DAO ben?tigst, k?nntest du in VBA runsql strsql$ - -- - ADODB. . . . ich muss dann also tats?chlich ?bers CommandObject gehen? Global obj_conn As ADODB.Connection, netz_conn As ADODB.Connection Global obj_comd As ADODB.Command, netz_comd As ADODB.Command 'Das