<> </P>9 h$ @+ ?7 M p
<>Creates a new Recordset object and appends it to the Recordsets collection. </P>3 ~" E% z2 a; b
<> </P> 8 \$ S0 B" E N5 l, K: w8 l<>Syntax </P> 5 Y+ }3 u- x, S; o5 o3 f<> </P>8 K& Y3 v) z2 u
<>For Connection and Database objects: </P> ) n& \! `" u. d- {1 y<> </P>6 U" t7 [* J- y9 n
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> : @% V" v6 H9 @/ Y<> </P> ( G- E6 K7 c1 }% i/ A+ R<>For QueryDef, Recordset, and TableDef objects: </P> / T' b" d, _/ p8 v5 ^<> </P> : M7 T3 Q2 w: W' \$ k1 o<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> 2 }$ S; i/ ]. f! C<> </P> 7 C6 U9 s# X- T* x' z' o5 ~<>The OpenRecordset method syntax has these parts. </P>5 c" }+ D9 j$ ]
<> </P>& Q: ?# r% Z8 A6 R: Z" G
<>art Description </P> 1 z( {6 Y1 T* k/ A! y" p<>recordset An object variable that represents the Recordset object you wantt to </P> . P/ i6 N6 T9 Q g% f& t) U, R7 `3 E+ Q<>open. </P>4 y. G+ r ~) f" Z4 l% h
<>object An object variable that represents an existing object from which you </P> 9 U. Y6 o( g4 {& u<>want to create the new Recordset. </P> 8 ?; S3 N, W; d# \<>source A String specifying the source of the records for the new Recordset. </P>, g, N9 W3 K1 @
<>The source can be a table name, a query name, or an SQL statement that </P> M' a: |1 a4 p% C P4 [8 I
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>- h. H* ?. z+ Q; i+ V+ [3 V* k! y
<>the source can only be a table name. </P>* T, O6 v' ^# N w
<>type Optional. A constant that indicates the type of Recordset to open, as </P>, O7 s. ?( L- m* y6 |/ R, W- ]
<>specified in Settings. </P>" ^0 ]; C# H6 }' a3 ?, [
<>options Optional. A combination of constants that specify characteristics of </P>8 z3 M n) s! ^* T
<>the new Recordset, as listed in Settings. </P> 6 y0 E3 e- M6 N) H( Y<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> 0 S0 s4 E- H& y/ J% L<P>as specified in Settings. </P>6 c; w4 J3 H+ m' l# }. f
<P>Settings </P> % _- ]5 S% L- Z" I<P> </P>/ ?. o* d+ v; n' i0 C
<P>You can use one of the following constants for the type argument. </P> 4 N+ k% D% R Q) z<P> </P> 5 ^4 b! O- Z5 P; z/ q& E9 r<P>Constant Description </P> 7 Z. W% U7 [" ^ r- f, V9 L<P> </P> ! q$ u6 }, |6 }/ e. l4 d<P> </P>2 q' L& K @- N S. [
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> 8 m" O5 g P- e0 z' B6 b<P>only). </P> / c5 S+ a! r" {, Y; ^ p) B<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P> 6 x5 D- U- A: e, q- @' V. P; H/ z<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> - `8 d# e) H5 g( [<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> " _' p0 D9 x. R; c5 o<P>ODBC keyset cursor. </P> + p2 C, e- v8 O% d0 k5 O& Y4 d<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>7 U3 z2 t, X- |# W5 k8 R
<P>ODBC static cursor. </P> 8 T8 t3 s ^1 o \8 L3 n* s5 S) A<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P> , [- v: B, }1 T% F; ]<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>) c7 F W" j2 l6 L* M4 `( E( f
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> % K' e7 E% \6 b3 R% B$ w<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>/ r5 z! `0 v6 Z# P6 l
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>3 ^9 ]' Q/ k$ M4 ~: t% X' ^
<P>y. </P>: D& J# ]& Q- e0 T
<P> </P>$ M" z) q6 |8 y x. v; j6 Y
<P>You can use a combination of the following constants for the options </P>8 p. y6 s/ d3 T8 g/ n
<P>argument. </P>3 o% ]5 E9 n% L1 G# K/ ?
<P> </P> + m( l+ |* V- a<P>Constant Description </P>/ E5 J3 b6 l8 W- Z
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> 0 ]* r, ], G, N% M! A<P>prevents them from editing or deleting existing records (Microsoft Jet </P> {% X& u8 B' a8 W
<P>dynaset-type Recordset only). </P>+ E! A" t& |8 \: F
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> ! m* {/ Z# Z9 A4 J6 k- X<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>) `+ `3 _4 Q5 F1 y5 o. x9 E
<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> 4 @6 E5 X7 `+ k7 p# U<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>) Z" d4 W }+ W; A! w/ A9 }
<P>useful in applications where multiple users have simultaneous read/write </P> / e1 [; @/ U) i1 ^ P<P>access to the same data. </P>& S, ]" Q0 U9 C: Z; i0 _
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> . m2 b0 u% a4 ~& D6 |<P>Jet Recordset objects only). </P>0 [: r8 k. z2 H
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> M+ }# C6 W4 s1 ]1 N; i+ p<P>table-type Recordset only). </P> 5 z; X: L; Z1 N' @<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>! H7 w/ }2 J, d5 ^
<P>Recordset only). It is provided only for backward compatibility, and you </P> 5 g! t- |' V# J<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>& z+ }' y1 I0 |& g. O( c
<P>using this option. </P>( f% M, o" [9 K* l$ {& _- Q
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> & j& b# f7 Z6 G9 g% L5 l) W<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>& O6 {2 N9 C) o6 R
<P>option, which is provided only for backward compatibility. </P>; R. `' Z7 i0 c6 A# ]6 V3 o
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P> / M5 E% r6 s# o<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> * O" u8 j9 d2 x9 t( c<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> ' E5 V. ~0 h5 Q# t1 a p<P>not opening a Recordset based on a parameter query. For more information, see </P>; O7 `" S2 C0 I, j
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P> ) ~; y$ v" @ X! l7 e4 ^<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>/ F1 o0 q e- \. ?
<P>snapshot-type Recordset objects only). </P>: \3 L: D/ W! o; R3 ^
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> o9 d/ c2 P, R# R<P>snapshot-type Recordset objects only). </P> 2 x& Z" v b8 z7 D Q<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> t; f0 |6 D& s4 l0 k<P>and using both causes an error. Supplying a lockedits argument when options </P> - Z2 X. ^2 V3 Z! X<P>uses the dbReadOnly constant also causes an error. </P> * A2 G8 E/ ~# }' N6 m<P> </P> + C' n! j- x8 ~5 n$ Z( d0 l( ?; M4 z8 x- x<P>You can use the following constants for the lockedits argument. </P> & @& X; J2 \2 n' o, @$ V<P> </P> $ M5 X s- @# A8 z3 Z- ]9 h, G- ~<P>Constant Description </P>3 h M: J& e8 ?* x# t* D9 R
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>7 g" ^2 N x& h% B
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>$ m0 o# \! `; h# J. ^
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>" w2 I4 f% Z% ]
<P>run-time error occurs. </P># B5 o) n/ B' F' U4 M, R% y
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> 7 D* `5 j5 x6 f7 G C) @<P>the Recordset in a multiuser environment. The page containing the record </P> 4 n K) \# c* t7 D! E# k& h2 y' y% D<P>you're editing is locked as soon as you use the Edit method (default for </P> 3 O8 Y0 W0 h* {" f! V1 |/ \/ Y' Z<P>Microsoft Jet workspaces). </P> 2 M! P; Y! Q- G, [ C& H<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> & l, O( u( D& `- v" x+ S8 n( z<P>Recordset in a multiuser environment. The page containing the record is not </P>0 U+ a0 U$ D% C+ {
<P>locked until the Update method is executed. </P>4 X, Q2 }3 j7 E) r+ A* }7 ^/ L3 Q
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> . v$ U- O3 n3 W" b! K<P>workspaces only). </P>( U7 }" X+ b1 W) C2 o/ k
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> 0 R3 B- B5 n; n; G: A3 |" u<P>only). </P>4 k6 u' b# }6 R0 `
<P>Remarks </P>8 j- g$ d! O2 U6 a, X
<P> </P>8 \) ?7 [! Z. W! E. [$ f
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>3 ~: ?" P( D& @4 T, L, B7 M
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>; W* J! V0 I2 c4 ]- i) \
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> 0 `1 s6 A; X6 X! r- x. h. n0 p<P>the type argument; if you do, a run-time error occurs. If you want to use an </P># A7 J/ I; G6 I
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>5 g. q+ B# t% @4 b$ F2 R
<P>data source, you must first set the Connect property of the linked table's </P> ' ~9 H: a; T% g<P>database to a valid ODBC connection string. If you only need to make a single </P> 3 N: f- T7 b4 S: }( j$ |8 ~ ^+ O<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> / V; j1 O. h# q$ T, E, V: Q9 M% g, E<P>source, you can improve performance by using dbOpenForwardOnly for the type </P> ! ~3 ]! D" a+ [( J* l<P>argument. </P> ! g! H/ L% z& K( b: L" d6 A<P> </P> 9 ^. x7 g: Q6 \3 Z<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>5 q. k1 ?! a" P4 [+ _& |& a
<P>is of the same type object. If object </P> 9 o/ N( ~ }" ]& Z" |0 z<P> refers to a table-type Recordset object, the type of the new object is a </P>3 T- c5 i; z! D' H2 V
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>- R3 ^5 Q- N1 u; Z4 R" k3 Q& R
<P>杢ype or ODBCDirect Recordset objects. </P># G; A2 M6 l0 ]% |
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> 8 c' B# g u5 h4 b. C; D' S<P>select query in the source argument, such as </P> ! }4 _+ U" H% v<P> </P> 6 I5 T& L/ m$ ]2 B<P>"SELECT LastName, FirstName FROM Authors </P># ~* c C0 `# o, j
<P>WHERE LastName = 'Smith'; </P> & H. c2 }$ G, Z0 \! S<P>SELECT Title, ISBN FROM Titles </P>( P$ e8 x' ~% P. F& i. X7 t+ f
<P>WHERE ISBN Like '1-55615-*'" </P>$ s- O5 @+ }* P9 z- P# K) q
<P> </P>% Y ^8 j4 L; K9 Y0 g0 @
<P>The returned Recordset will open with the results of the first query. To </P>! m# E7 Z# B% F' ^# j/ J
<P>obtain the result sets of records from subsequent queries, use the </P>6 X; D, Z$ J" y
<P>NextRecordset method. </P> " B( o! r* y4 D& x* [6 s, k<P> </P> . W7 Y2 m6 e" p3 I* F" E<P>Note You can send DAO queries to a variety of different database servers </P> 2 J- R4 H: R' O! g# c3 I A<P>with ODBCDirect, and different servers will recognize slightly different </P> % a" z: E+ Y. b2 C" M0 V/ S<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> 0 f) }( I% m; s8 S% j$ l# f<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> " U% U3 k' {* `+ \- @ \ o<P>included through the Help menu. Be sure to check the appropriate reference </P>) K; L. x% T, R: O
<P>documentation for the SQL dialect of your database server when using either </P> 3 m% s4 U" }0 {: _& L<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> 3 O: I% ~# l# g) A K- [ Z# \5 |5 t<P>client/server applications. </P># C7 ]0 O% ~0 H4 E& s
<P> </P># _. p2 [0 H9 h6 S
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>: x/ K3 u! K" \/ p$ p& V" d1 j
<P>trap changes while two or more users are editing or deleting the same record. </P>& q' y+ O0 S+ V5 F* s! z( n
<P>For example, if two users start editing the same record, the first user to </P>+ w7 W' B8 p9 Q% f
<P>execute the Update method succeeds. When the second user invokes the Update </P> - E$ H- C9 y2 a8 b<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>" D7 b$ q' F6 K! K
<P>the Delete method to delete the record, and the first user has already </P>! Q/ V4 |/ P5 ?6 |
<P>changed it, a run-time error occurs. </P> ! _0 o' d K6 g4 a, ~<P> </P>+ L8 ^3 Z$ s5 \3 j' I8 k
<P>Typically, if the user gets this error while updating a record, your code </P> ( ^4 Q9 q# \/ l+ I$ D( M1 y" ]9 i+ q6 I<P>should refresh the contents of the fields and retrieve the newly modified </P>. F) X& r, d/ }5 ]8 i& K
<P>values. If the error occurs while deleting a record, your code could display </P> ; k+ }: g4 S% N1 p9 V# r0 F6 d5 @$ d<P>the new record data to the user and a message indicating that the data has </P>& f" W5 }% }6 B6 _6 K% |
<P>recently changed. At this point, your code can request a confirmation that </P> 8 _! X' Y: S! W ~( ` O& O6 U, u, c( z<P>the user still wants to delete the record. </P> + e. m+ I( t( e/ Q( Z<P> </P>, Y; X/ c+ A$ z* h
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>- Y3 ~, r }+ [+ n$ K. V
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P> 3 D* _9 G2 k$ B( F( Q/ O, M<P>later) table that has an IDENTITY column, otherwise an error may result. </P> 4 m& h. Y0 _3 b3 R/ J<P> </P> 3 N0 i; A( b. m* j0 p, a( K( ~<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> L0 D$ y5 p# u4 u+ W4 \% `8 W<P>the dbRunAsync constant in the options argument. This allows your application </P>5 ]2 N7 \) F' w1 b, u: U
<P>to continue processing other statements while the query runs in the </P> . U1 f* K% e; v1 |<P>background. But, you cannot access the Recordset data until the query has </P>! l/ A8 s! W$ W7 S! x
<P>completed. To determine whether the query has finished executing, check the </P> 9 H6 ^: ?; [6 E$ _7 ]0 K<P>StillExecuting property of the new Recordset. If the query takes longer to </P>" I. I) d% d9 T" a) R1 x% L
<P>complete than you anticipated, you can terminate execution of the query with </P>( T* ?2 j7 P4 Z. j1 d+ T
<P>the Cancel method. </P>' n: N+ G+ u X5 f, q8 I! |
<P> </P>, a9 v! q+ e3 q. q
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> , B8 w8 S) G. j4 M' y+ K8 q3 q+ Q<P>connection is busy with a prior </P> ; n9 w3 s- f) k1 E1 d- p9 Z8 C* g<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> # ?* O- N1 @0 k& p<P>ODBCDirect, if the server supports this. Another solution is to fully </P>5 O! @2 a! ]% u
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> ( v) I; m6 c! [3 U% l<P>is opened. </P> # G9 w& ~6 L$ V$ n4 U9 |0 I<P> </P> 8 p* R" O9 w( e) X: c<P>If you open a Connection object with DefaultCursorDriver set to </P> ) C! X, u( K) o. c<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>" P. m n7 H2 ]: q+ B' D
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>/ u) \3 ?& [' G! R; `
<P>h in the lockedits argument to enable update caching. See the Update method </P>: \( E& b, _" ^, l$ |) B
<P>topic for details about how to write changes to disk immediately, or to cache </P>" ?9 ^5 k% H7 [' |* W7 ` `; }
<P>changes and write them to disk as a batch. </P>- s% ~0 N, `) ?) P9 ]) b
<P> </P>8 y) r) d9 W6 X% l/ L/ h0 J8 y' ~. C
<P>Closing a Recordset with the Close method automatically deletes it from the </P> 9 E/ U' G+ h8 t3 Q* [ 6 C% f# x+ r6 H# ]1 Q<P>Recordsets collection. </P>6 @* T. `* V7 Y ?5 E- `7 ~
<P> </P> : Q& O4 x8 J) V) f+ ~) ]. M<P>Note If source refers to an SQL statement composed of a string concatenated </P> 6 F. g9 h/ _0 P, W<P>with a non-integer value, and the system parameters specify a non-U.S. </P> * p# Z% j! l1 m<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> 7 b7 x5 J! {" A# F8 u<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>& i! s" n0 D* @( k9 `
<P>Recordset. This is because during concatenation, the number will be converted </P> ' v$ Y) h+ Y( g<P>to a string using your system's default decimal character, and SQL only </P> ; P: i7 K$ o+ y; A( i$ e<P>accepts U.S. decimal characters.</P>