<> </P> . B7 q' F4 X9 r<>Creates a new Recordset object and appends it to the Recordsets collection. </P>1 T" @& \1 r* l- T/ h0 R; C; p; p( [
<> </P> : m. U X: o6 U1 J' ]+ f<>Syntax </P> z' ~8 |' Q' L" @; C( b<> </P>3 c8 X; ?' F$ A1 C, R
<>For Connection and Database objects: </P>; k* A; G' I* `; ~9 `- y
<> </P> 6 \& d( r6 \8 z* }- N<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>9 m) O2 q1 M& V& B& u8 K* P
<> </P>8 G2 _/ u5 a3 i/ v; e7 S* z( |5 X+ ^
<>For QueryDef, Recordset, and TableDef objects: </P>% }0 S Y# n9 p9 }
<> </P> ( z( m; t7 ^, Z; @7 b& x+ o<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> ( {6 ~$ |+ F% z" d: G<> </P>! B/ p8 e/ b/ ^ I; K9 s
<>The OpenRecordset method syntax has these parts. </P>; @9 r( | `* t
<> </P>. h! {& s# {! S8 y g' W& y4 x7 P7 q/ y
<>art Description </P> + \" W, ~' {0 M* s. i" N<>recordset An object variable that represents the Recordset object you wantt to </P> / X8 J! b! z4 s<>open. </P> ' p3 G9 c/ O9 _8 R; v. s<>object An object variable that represents an existing object from which you </P> + j! @( ^. R+ i: v1 v3 _<>want to create the new Recordset. </P>7 w* k" R8 L3 h- ?5 l7 c* h2 t% ]8 H/ w
<>source A String specifying the source of the records for the new Recordset. </P>! T) V% ^1 T2 |# N" x% I* M
<>The source can be a table name, a query name, or an SQL statement that </P> 8 o+ X/ [6 e* N" K: Z, ^4 Q0 b9 m<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>2 W R Y9 J- ?
<>the source can only be a table name. </P> + M/ e- v$ x7 W* W" k/ \* v7 O x<>type Optional. A constant that indicates the type of Recordset to open, as </P> # |3 h6 |+ L- {6 v9 V8 ~7 f<>specified in Settings. </P> + @0 A0 l4 @6 C4 u- e( v2 X6 [4 Z<>options Optional. A combination of constants that specify characteristics of </P> + S5 F9 ]/ q9 R7 N<>the new Recordset, as listed in Settings. </P>: m: w# X: A' a+ ^+ Q& O! T2 W; y
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P>" ^! f5 ?# t3 f* `+ t) a' a. S; i
<P>as specified in Settings. </P> 0 Z. @) z" W5 \- s0 D, u" _* ^<P>Settings </P>: t, k( s5 K3 H
<P> </P>% C( e& k# k* `# p( j
<P>You can use one of the following constants for the type argument. </P> ( d E' C* f# R- C$ P6 _<P> </P> / V8 }, x8 a) Q, \<P>Constant Description </P> # Y8 ^; R1 F3 [) ~ x8 }: V* h G<P> </P>9 ]: x. o6 p/ o2 ~2 G; w% @) [
<P> </P>4 K/ y" Q" t$ U
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P>. J1 h9 y: t/ w; F t
<P>only). </P>1 E, S" b x+ r$ k" }4 C- Y3 z
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P> % U; w1 ?/ y/ F' V9 w% N( H4 b<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> 5 l! T0 K) \" \) y<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> ! j6 \3 ~. s, ^- h# K* ?( a Z, t8 T<P>ODBC keyset cursor. </P>4 m! @1 e/ V! n; K- i. l9 p. v: H
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>, E! n) k9 Q. c3 T- z
<P>ODBC static cursor. </P> } r! T- [' v, l: ^/ Z
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>/ _& ~1 Y8 ^1 l% c0 }
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>' @. E9 f8 Y% R, b
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>7 o. @' K+ U+ Z" o
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P> 4 `( |9 [ p' e# W<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P> , ?/ q/ k. \; e3 x3 h, u; f<P>y. </P> ( _: s4 e* A L; M$ c( }/ `<P> </P>' t, o' z% g; Z6 i( a* M3 M+ Y: @
<P>You can use a combination of the following constants for the options </P>! W% L7 Y+ o) ~; u- v4 p
<P>argument. </P> 6 P1 u( k: x) c5 y) d6 j$ N: h3 ~<P> </P> . j6 ~/ Y4 K6 ~ H<P>Constant Description </P> B8 J; [1 c: n<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>0 z' |3 K* E: N7 J. c% x! G( R
<P>prevents them from editing or deleting existing records (Microsoft Jet </P> 5 c1 w a8 o o' a' M<P>dynaset-type Recordset only). </P> / W+ b+ s3 u2 w+ C. b: L<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> / T* d1 p. ~: i+ `" G2 z9 N! X<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> 6 x3 T, X/ W0 X1 `$ ^4 n<P>dbSeeChanges Generates a run-time error if one user is changing data that </P>* m( Q' V$ Y8 ~
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>, W _9 y5 B: K+ c& `- A2 C& r
<P>useful in applications where multiple users have simultaneous read/write </P>1 Q. ?( _) q6 D- N Z' I: N
<P>access to the same data. </P>0 x1 W% c4 {( {" @
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> $ f" l# Z0 g! J5 N7 M( \# i+ B<P>Jet Recordset objects only). </P> ! \1 l7 a/ L5 T0 L: B- V<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> 8 @# T' W& K# i<P>table-type Recordset only). </P>* G/ g; H4 Q7 _" w7 [# E, t8 W
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> $ \( L. J9 J; h. F/ ?2 N3 E3 P<P>Recordset only). It is provided only for backward compatibility, and you </P> 0 A* c3 u0 x2 n( s9 k<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>% ~* F/ d/ R# X; Y1 B4 p
<P>using this option. </P> / s4 P1 t2 L8 Z<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>6 j& n5 z' ~% p7 {2 w+ L
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>7 ~# b5 e/ s. ^) a2 Q' E& X
<P>option, which is provided only for backward compatibility. </P> , v, r4 _# Q8 D+ L/ V<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>( ^, i9 V' }7 X# _
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> 4 V% R, n7 H& ?, Y1 _<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> ' g4 R' [+ {5 `4 _9 C% b<P>not opening a Recordset based on a parameter query. For more information, see </P>. |, [% O F) j6 G. v
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>- ^' \4 R8 l4 A
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> , w4 V, l& q: P- d<P>snapshot-type Recordset objects only). </P>+ i( I$ L- F6 M3 f0 c# S8 [
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> 1 [9 B* M, z; U, O1 \<P>snapshot-type Recordset objects only). </P>. t# b. i8 o! N0 X
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> 5 o& z( S" G& P3 P. i' `/ E<P>and using both causes an error. Supplying a lockedits argument when options </P> 5 l$ Y: K$ ~9 X5 ^, }6 a& @; I<P>uses the dbReadOnly constant also causes an error. </P> i! i# A+ O3 U! K1 w6 e7 {<P> </P>, Y8 ^5 o9 @" R/ K. ?+ A! P
<P>You can use the following constants for the lockedits argument. </P> & S; \& \; w5 _8 i. n- ]- E/ n<P> </P> : z& h' w. f$ Q ?. F<P>Constant Description </P> & l" |* S; x" r" W2 u) V) p<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> ' i* m1 a$ t3 d( n<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> % O: l6 c, p5 i; D<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> X, B. V4 Z, d& a# c* Q0 a
<P>run-time error occurs. </P> ( F b' B% o* {<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>: ~+ O6 o9 S( ^2 n
<P>the Recordset in a multiuser environment. The page containing the record </P> 8 d+ }; F% h* C5 Z1 E" }0 G<P>you're editing is locked as soon as you use the Edit method (default for </P> , \& z7 {% C/ ?<P>Microsoft Jet workspaces). </P>4 g! p6 I. k) s+ Q% `9 X# v8 c2 n
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> : X) l# [3 N8 \; z<P>Recordset in a multiuser environment. The page containing the record is not </P> 8 R1 v6 _) w3 ~9 w: J<P>locked until the Update method is executed. </P>+ K' |! o% d; x- \: B( i6 A- J
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> ; F) _6 K5 v9 S# E/ a! }$ ]<P>workspaces only). </P>/ p4 _' @% ~$ v! X1 h# B$ A$ C
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> ) W, {1 i6 W- o( E6 N<P>only). </P> 2 U% I$ e1 l4 X0 S/ ]2 H8 k' C<P>Remarks </P>: h2 J9 l# o6 H; E! D) d1 e. h
<P> </P> ! `1 |" v, |& N: @<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> # Y1 `& _" {5 y6 p- r$ B4 v. j<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>& x2 Z9 x J# y5 A/ a
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> k8 P# e' B" X, G2 c<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>% g6 W. M$ M% y( K, |0 Y% X
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> $ \$ a4 l$ L) i* X; k<P>data source, you must first set the Connect property of the linked table's </P> : o- j( h9 s9 i: G5 h<P>database to a valid ODBC connection string. If you only need to make a single </P>0 _/ d6 E& e3 X4 v
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>$ z! y7 D* {% n0 r$ W
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>- v3 f4 c0 R% T% m" Z/ K
<P>argument. </P> 7 p0 d3 H4 @1 u8 W& H: ]<P> </P>2 i/ m& V6 S9 D
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>0 @) V% c! c8 L6 d8 b }
<P>is of the same type object. If object </P>9 _" {! b* j1 { [- B+ Z3 U0 e4 ~: F
<P> refers to a table-type Recordset object, the type of the new object is a </P>- c3 {4 I. Y" _8 e* B: w
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> ; C/ j+ G- b7 o0 m. I<P>杢ype or ODBCDirect Recordset objects. </P> $ i* [' ]% J N<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>$ v' ^4 |# V7 L. h) n7 \
<P>select query in the source argument, such as </P>2 K# @9 ^( j& b" d% Y
<P> </P> 8 O- n+ v6 U) ?6 w9 I8 Z<P>"SELECT LastName, FirstName FROM Authors </P> / g% D+ Z$ o! v. @$ k. d<P>WHERE LastName = 'Smith'; </P> + q6 @5 {; a" ?7 E<P>SELECT Title, ISBN FROM Titles </P> : O5 c; a, f7 {6 X3 r a<P>WHERE ISBN Like '1-55615-*'" </P> : s! ~" n8 [' ~6 i% Q2 `# {+ i<P> </P> - m8 k0 J2 ~0 C& l<P>The returned Recordset will open with the results of the first query. To </P>* }; F2 R" t1 u+ z, z6 D
<P>obtain the result sets of records from subsequent queries, use the </P> 5 \ [3 H) Y2 V<P>NextRecordset method. </P> - C& G1 Q- R1 f. Z0 @2 d, @& ?& b% J<P> </P> 0 M: }. u. p1 C, Z: i) X" z<P>Note You can send DAO queries to a variety of different database servers </P>4 J9 E J5 j; ]
<P>with ODBCDirect, and different servers will recognize slightly different </P>" e4 H5 |! i* P- h/ _1 J7 E
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>- H0 J! J) Y. n( J4 [% H4 g6 X2 t
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> 6 v5 ?+ A, F' W8 h$ I1 }$ T<P>included through the Help menu. Be sure to check the appropriate reference </P> $ A7 t' b2 f+ W ~9 P' P<P>documentation for the SQL dialect of your database server when using either </P>2 |* \4 k) L0 x- k6 p, W
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> 3 C# F9 |8 {1 ^* d9 s4 A1 V<P>client/server applications. </P> 2 w, `; ~; l" r' _1 p<P> </P>) w: J7 ?* T+ P
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P> & x% O/ W$ L, i2 L* e<P>trap changes while two or more users are editing or deleting the same record. </P> * i7 @/ c* [1 l<P>For example, if two users start editing the same record, the first user to </P>$ A8 [6 D" P$ U
<P>execute the Update method succeeds. When the second user invokes the Update </P> & w3 b/ z. M& S9 |8 E, W<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> 4 \7 `2 [* F' D6 e<P>the Delete method to delete the record, and the first user has already </P> 4 _1 v5 e0 z7 e1 y6 u5 S<P>changed it, a run-time error occurs. </P> m7 S: ]9 C1 I1 W- X% F8 U+ o) ~" ~<P> </P> , u/ R5 A# L6 W7 T/ z<P>Typically, if the user gets this error while updating a record, your code </P> ' i0 A+ g/ Q. c& W: ~& n<P>should refresh the contents of the fields and retrieve the newly modified </P>, L6 Z4 C+ \; k7 s5 D* U
<P>values. If the error occurs while deleting a record, your code could display </P>( V! H' T2 o4 w# X0 \
<P>the new record data to the user and a message indicating that the data has </P> ) M3 Q2 B, _2 D7 a<P>recently changed. At this point, your code can request a confirmation that </P>0 f* n5 P' V4 h. \
<P>the user still wants to delete the record. </P> * G* K- H+ z6 a0 s! s& f<P> </P>& P4 R; i, m1 Y; S" M
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> ) j+ n s' }* J3 O% ^. o<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P> ! F0 C' [/ l8 X! O2 Q' K3 @% p<P>later) table that has an IDENTITY column, otherwise an error may result. </P>1 s; b# [% K% ?
<P> </P>! I/ \" x$ w. J5 O! |4 J9 P/ l, ?
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> - _6 F( U6 M$ O) d! N<P>the dbRunAsync constant in the options argument. This allows your application </P>5 n% n* @# x! C$ N6 u! G% x# I' A4 P
<P>to continue processing other statements while the query runs in the </P>- U% c0 S8 Y: H+ v+ G& O! N- k
<P>background. But, you cannot access the Recordset data until the query has </P>9 H: t0 N7 o& i) M
<P>completed. To determine whether the query has finished executing, check the </P>6 y+ U- x4 u( v1 Z
<P>StillExecuting property of the new Recordset. If the query takes longer to </P> 1 G+ |* h; G: c% h<P>complete than you anticipated, you can terminate execution of the query with </P>: Y) D/ C7 r. K k9 o" X
<P>the Cancel method. </P>$ k* b- z# a' T/ O% }/ z
<P> </P> * M( ]3 s! D4 t' J# l<P>Opening more than one Recordset on an ODBC data source may fail because the </P>$ z8 r/ ]! U) p# t* b, u
<P>connection is busy with a prior </P> # v' M( S3 P% A y! k+ {<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>$ l3 f4 }5 X7 {! j4 S
<P>ODBCDirect, if the server supports this. Another solution is to fully </P> ) n$ z: m- _6 @9 {, }0 {: S& Y<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>6 o8 S1 r6 }( i z9 v
<P>is opened. </P> & a/ I, v& K8 \4 ]0 }- }<P> </P>! n7 S2 m/ z( u! X% G( z
<P>If you open a Connection object with DefaultCursorDriver set to </P> $ a% \" I; k& A) L* }6 v/ u<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> + L9 x P: m0 m( I' A. I+ a<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P> + ~; B |) D( L9 d9 ]3 e<P>h in the lockedits argument to enable update caching. See the Update method </P> # S/ W. u# b6 }/ i; }<P>topic for details about how to write changes to disk immediately, or to cache </P> ; D- ^9 `* h" L+ x8 s<P>changes and write them to disk as a batch. </P> ! G' V( Y* D9 _7 ], O! V0 Q$ f<P> </P> ( L( l5 T, j& q/ D/ R" L. G; L<P>Closing a Recordset with the Close method automatically deletes it from the </P>, h" v& G/ N6 x9 y6 c0 ]% e
- R/ T+ \# }& y* h8 R7 q/ Z
<P>Recordsets collection. </P>9 R- W: b0 ]. |) K' K
<P> </P>. o" ?% Q7 b! T1 ?+ }" T& y) P
<P>Note If source refers to an SQL statement composed of a string concatenated </P>. Y/ c/ E' F- e9 ~0 T; S1 `6 [$ L
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>" ^7 }( \4 T5 ?, s7 V4 S
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> 9 M, T2 t, B/ X: }. w. G0 Q<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P> 6 p" f' z+ i2 b" m' R# \& Y2 H<P>Recordset. This is because during concatenation, the number will be converted </P> $ ?( M- \" H( }8 H<P>to a string using your system's default decimal character, and SQL only </P>; k+ y# G' Z' Y! g. M2 u
<P>accepts U.S. decimal characters.</P>