Jim Lawrence (AccessD)
accessd at shaw.ca
Sat Nov 8 22:20:19 CST 2003
Hi Jaun:
Only an ADP Access form can connection directly to recordset otherwise an
ODBC connection string can but that is one layer up from ADO-OLE and
performance tend much reduce especially if you have just requested a large
group of records. I tend to dynamically link and lock the recordset, instead
of the forms and use code to feed the forms. I am sure there is other
methods. I posted the following code a week ago but you might not have seen
it:
code >>>
Public mobjConn As ADODB.Connection
Public gstrConnection As String
On Error GoTo Err_NotConnected
' if your are connecting to MDB database
gstrConnection = "Provider=Microsoft.Jet.OLEDB.4.0; _
Persist Security Info=False; _
Data Source= MyDatabaseNameAndLocation"
' Test connection string
Set mobjConn = New ADODB.Connection
mobjConn.ConnectionString = gstrConnection
mobjConn.Open
MsgBox "You are connected "
Exit_GetConnected:
Exit Sub
Err_NotConnected:
MsgBox "You are not connected "
Resume Exit_GetConnected
..........
and everytime you want to connect after that...
Dim cmdInvoice As ADODB.Command
Public rsInvoice As ADODB.Recordset
Set rsInvoice = New ADODB.Recordset
Set cmdInvoice = New ADODB.Command
' accessing a parameterized query in a MDB database
With cmdInvoice
.ActiveConnection = gstrConnection
.CommandText = "MyQuery"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("InvoiceCode", adChar, adParamInput,
10, strInvoiceCode)
End With
With rsInvoice
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open cmdInvoice
If .EOF = False And .BOF = False Then
.MoveLast
GotInvoice = True
End If
End With
...or direct, no command section needed
With rsInvoice
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open "SELECT * FROM Invoice " & _
"ORDER BY [Group]", gstrConnection
If .EOF = False And .BOF = False Then
.MoveLast
GotInvoice = True
End If
End With
<<< code
HTH
Jim
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of MastercafeCTV
Sent: Saturday, November 08, 2003 1:51 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] ADO Connection from FORM
We are trying to connect from a FORM to and external MYDATA.MDB on a server.
We are sure that ADODB could be use but we only use ASP forms to make this
and put over the server.
On the ASP page is very simple to connect :
<CODE>
Set Ob_Conn=Server.CreateObject("adodb.connection")
Set Ob_RS=Server.CreateObject("adodb.recordset")
Ob_Conn.Open "Driver={Microsoft Access Driver (*.mdb)}; " & "Dbq=" &
Server.MapPath("datos.mdb")
Sql= "SELECT * FROM productos where familiaid='"&cadena&"' order by
codigo"
Ob_RS.open Sql,Ob_Conn,adOpenStatic, adCmdTable
Ob_RS.PageSize = 6
Ob_RS.AbsolutePage=Session("pagina")
</CODE>
But to make the same on a simple FORM like a RecordSource?? Or in VB into de
form to collect some data to visualize ??
Thanks
Juan Menéndez
===========================================
MASTERCAFE SL - NIF B-82.617.614
www.mastercafe.com
Deleg. Asturias
Tel 985.88.49.44 / 627.531.764
Fax 627.500.205
info at mastercafe.com
juan at mastercafe.com
Deleg. Madrid
Tel 627.474.285
cecilia at mastercafe.com
===========================================
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com