<> </P>8 g8 v5 ~+ w2 @6 a
<>Creates a new Recordset object and appends it to the Recordsets collection. </P>5 ?3 N; q3 m+ s* G1 b* F) d# o# D
<> </P>9 c" i1 `" j, N p9 e5 _9 I1 A
<>Syntax </P> / U" k& l2 G" b! k: e' G<> </P> # c1 F5 J/ U; o$ {0 s4 M# p9 Y9 y<>For Connection and Database objects: </P> . P6 _* i! }7 s; l; {" E: Y<> </P> % B6 O$ K+ K- z* E1 M4 E<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>! l W( T/ q2 z" b1 H/ d, h! ^
<> </P>( @# P% f* G, D$ J2 @3 S/ p
<>For QueryDef, Recordset, and TableDef objects: </P> 0 C" o, k$ a$ f) A X% o8 W<> </P> ( C" J; P# K W8 T Q<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> & Y3 H2 Q! m/ P0 J! |+ i3 C) q<> </P> Y/ j0 m% U6 A9 q1 }: c6 Y. z0 z6 ]
<>The OpenRecordset method syntax has these parts. </P>& y4 |; _- { Y' c1 [& J5 x
<> </P>! z5 n8 z5 l" Q5 j" \$ F
<>art Description </P> 6 ~# n% O# X" w7 U6 s6 p<>recordset An object variable that represents the Recordset object you wantt to </P>4 g4 I! v* _: G+ k
<>open. </P>! _- O6 l5 N T, E& b2 b
<>object An object variable that represents an existing object from which you </P># \' N. T& f! x. U
<>want to create the new Recordset. </P> : B& L* J+ _6 `5 o( ?<>source A String specifying the source of the records for the new Recordset. </P> 5 Z t. C) @1 }6 F) {8 Q( }+ y<>The source can be a table name, a query name, or an SQL statement that </P>( ]1 @# A9 Q* b/ u+ \: {/ Q+ S0 H
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> ( z1 r7 T/ O: ]) r+ _<>the source can only be a table name. </P> $ f& w: N5 A/ \0 r" r3 Z) Z<>type Optional. A constant that indicates the type of Recordset to open, as </P>2 d( v" v6 ~: [2 R" G
<>specified in Settings. </P> ) N& Q2 g0 Z- [& @+ p0 B8 t<>options Optional. A combination of constants that specify characteristics of </P>$ O4 T W6 T: m" k
<>the new Recordset, as listed in Settings. </P>" a- P8 y1 P: r8 |
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> / J+ e' l v! \& A5 ]2 I& {$ h: n<P>as specified in Settings. </P> $ k; q4 w) n/ O<P>Settings </P>. T+ p* v/ K( {, F
<P> </P>$ C. v2 A% E! f( P
<P>You can use one of the following constants for the type argument. </P> # l+ T; G$ h6 l! ]) H<P> </P> 5 L% T2 ]( R8 S# G! R<P>Constant Description </P> w9 ~' |- {, `& \$ I% l/ R<P> </P> 5 C) l8 M" r N+ i4 [2 B! s<P> </P> O( C; G8 R y0 L' X<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P>4 _! L: x( x Z/ n3 A
<P>only). </P>" ^6 K# X) d% [9 O# g
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>1 t ]* U. H1 r* r( f8 \% j* u
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>5 N" @; s2 X7 Y/ r
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P>1 b& p3 f* }. o2 x' h
<P>ODBC keyset cursor. </P>; r0 E! r4 [9 \
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>! M- }5 v, D: r2 j. \* v
<P>ODBC static cursor. </P> 7 W' ]3 ^' y, z1 J<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>$ p1 O) K, l& z
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>9 w3 {) f7 M2 k2 {0 p' {
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> 4 M: |3 v% `9 k D/ [! c<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P> ( u* p- X5 A G8 O<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>: h F0 e9 g. g8 K. E+ }, [ ~/ Q6 R
<P>y. </P> - E, y% \, f& x& N2 r2 V# F<P> </P>0 `/ b. z2 a# B# z
<P>You can use a combination of the following constants for the options </P>+ {9 F3 y/ k' q/ S
<P>argument. </P> 3 f7 ^8 u( y2 F# x' Z n<P> </P> t6 _5 \4 w8 t( Z
<P>Constant Description </P> 8 q4 ], V! ~$ X: ^/ q( C+ y<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>7 t5 P+ |- u/ g/ H) `
<P>prevents them from editing or deleting existing records (Microsoft Jet </P> 4 k. E" X! o0 g, _$ ]) Y7 |<P>dynaset-type Recordset only). </P>4 M) Z2 A8 C% b, D5 h5 M( h9 H, j& y
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> 5 l. g: r; C B<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>- T/ V& a( N7 v' C' A
<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> + t5 G4 d1 _& D1 O8 t+ o8 @; o<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>* W& B) m5 C# _& Q
<P>useful in applications where multiple users have simultaneous read/write </P> ; c" g( W% @1 b8 t4 E7 o<P>access to the same data. </P> % K1 t7 d! Y/ U8 Q$ Y( O<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>) @. j6 v9 [1 I* l+ a+ w* `6 s
<P>Jet Recordset objects only). </P>1 @$ M V$ }3 B3 ]
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> 2 v' d& K- s K+ R<P>table-type Recordset only). </P> 8 x- G2 ?8 @7 n2 x<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> # W3 c$ M" w! f; X; I9 S6 o0 C<P>Recordset only). It is provided only for backward compatibility, and you </P>$ Y( o1 e0 @! y$ ~# z7 x1 c {
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>. l! N4 _! q. n A% T
<P>using this option. </P>" j1 D7 T# e( e' ?
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>: _. O% ?0 N& T0 g7 c. \+ L
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P> , m! w( |& k# i- n" g" Z- g- a<P>option, which is provided only for backward compatibility. </P> ( i7 X( c0 Z9 C& h ~9 y<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>$ p) _0 }6 L9 v( h) [) m0 I
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> , c; u0 o/ {1 i1 t* v! e3 e- e<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> : j* Q( A& T2 T' s6 [; n<P>not opening a Recordset based on a parameter query. For more information, see </P> 8 ]/ W+ |6 _& O% U<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>$ V5 d& l: @, h9 Q8 N
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>5 N; K! F; q3 Y. w P8 y
<P>snapshot-type Recordset objects only). </P>; `( ?! n: X) J! D3 D
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>2 o& U; E, n( S% A" B
<P>snapshot-type Recordset objects only). </P>* Z8 R) x& q! [0 Y8 I# K$ m6 y4 o0 p
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> & C' s! s5 u1 L! ~<P>and using both causes an error. Supplying a lockedits argument when options </P> 1 x2 j2 `6 U8 [1 t) }7 ]( e# b' k$ w<P>uses the dbReadOnly constant also causes an error. </P> 2 A9 W' u. W, V4 v# M$ ]5 t<P> </P>& R! x, I: c x
<P>You can use the following constants for the lockedits argument. </P>0 a# {2 y: K9 G: V$ `
<P> </P> + L/ y; R( o4 A& K4 T6 `) _) P3 \<P>Constant Description </P>% _* X% u, B7 U+ j# p, p
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>3 u0 Q1 ~, b5 I$ `, b: P& v3 M
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> & o, ^6 _' p& q K# D" }<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> : Q3 T% `5 W/ u+ H6 [1 k, w<P>run-time error occurs. </P>& x2 t9 W5 u6 l9 m/ _- T/ `5 q
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> # o" B d. p' g9 `% W3 M9 l: z<P>the Recordset in a multiuser environment. The page containing the record </P>& z5 M( I- _/ ]3 r$ S7 {4 O% {" k
<P>you're editing is locked as soon as you use the Edit method (default for </P> , u, T7 J- x# b! x<P>Microsoft Jet workspaces). </P># q7 w7 K! V: H
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>5 S. W+ c' b+ Y* _
<P>Recordset in a multiuser environment. The page containing the record is not </P> 0 f, ?* g/ _$ y! U; d8 I<P>locked until the Update method is executed. </P>% o; U" r$ q, s @* w% [
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> 0 X" t8 g; l! Z' E6 l; [) f" Q( A6 B<P>workspaces only). </P> ; K0 g, n. U" D5 b<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>$ d: I; o4 E& e3 \; M$ S5 u% H5 b- A# b
<P>only). </P> $ ?9 u* r/ b/ l9 P. O2 ?<P>Remarks </P>* h) _) |8 ~3 }% N! s1 K
<P> </P>% n1 c! O! L+ U7 N: g) G
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>+ R) y4 h5 L0 E5 u- Y
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> G. X8 K4 V: B* Y0 [* h<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> ' I: i6 {" B% l4 t7 w" ]! p5 k2 t" L<P>the type argument; if you do, a run-time error occurs. If you want to use an </P># m: W5 M9 f7 m: d; t) a1 d
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>/ z: D9 g3 f; h
<P>data source, you must first set the Connect property of the linked table's </P> ; G4 e: a- F" c. Q<P>database to a valid ODBC connection string. If you only need to make a single </P>- R* F& f" J- {* o6 [
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> 0 M! }* K$ r) B" W# ]4 O1 j% }<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>( V. R( L2 J, j9 b4 D8 \( L) j
<P>argument. </P>$ j/ n# F+ W$ @$ v- ~( r/ U+ }6 o
<P> </P>2 Q- v4 a \! \3 w( E, S. o, G; i9 [# u
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> 3 R7 o5 E; R' x<P>is of the same type object. If object </P> , p# |/ M: Q3 V/ ]9 k" Y+ K<P> refers to a table-type Recordset object, the type of the new object is a </P>6 r+ v# ^; I8 }, @, F
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> . q+ ^ v6 Y5 I2 i& J' X<P>杢ype or ODBCDirect Recordset objects. </P> * l d/ n2 b8 D2 j8 w<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> % }( a$ m. S6 D: X<P>select query in the source argument, such as </P>: f& F# W$ ]3 r
<P> </P> . K& @1 ^. Z3 b: ` [9 z<P>"SELECT LastName, FirstName FROM Authors </P> % w9 @2 x% ^6 ?+ U/ _% D/ d6 C I<P>WHERE LastName = 'Smith'; </P>9 v! @. q8 _3 o) Y5 b+ @' M" ]
<P>SELECT Title, ISBN FROM Titles </P>' i G3 }9 C% Q1 P5 l
<P>WHERE ISBN Like '1-55615-*'" </P>7 b2 G; J! T5 a5 @
<P> </P>' C q) N3 u# o/ t! ]( N \' S
<P>The returned Recordset will open with the results of the first query. To </P> & u. v2 `) m/ t% @<P>obtain the result sets of records from subsequent queries, use the </P> ( @9 ]- z- y$ k$ J0 X<P>NextRecordset method. </P>3 z3 O1 w3 ^, _- H0 l+ h. q
<P> </P> / j+ S' p% J/ u<P>Note You can send DAO queries to a variety of different database servers </P>$ d9 e# s2 d A4 {) l# b
<P>with ODBCDirect, and different servers will recognize slightly different </P>0 M' Y! i& B5 m9 |; `. N
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>: z. g; I2 r7 v( F8 S
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> B r. N0 ]! S- y
<P>included through the Help menu. Be sure to check the appropriate reference </P> + S& L$ ^) x+ K1 k- i<P>documentation for the SQL dialect of your database server when using either </P> ; p9 Y8 y% i! t$ }3 ~<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> 5 b' r8 |4 s7 X! W<P>client/server applications. </P> * P9 [, \' _* a% C2 d! ~6 V5 H<P> </P>0 {0 a* E9 y6 |; }, Z6 Q
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P> 6 ?$ b3 V6 \1 `& ^+ J<P>trap changes while two or more users are editing or deleting the same record. </P>/ U) ^ a5 r" d! T& h3 N
<P>For example, if two users start editing the same record, the first user to </P> 5 E$ R8 n1 J' T% d m<P>execute the Update method succeeds. When the second user invokes the Update </P> , a4 v& _1 `: ^* g I<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>. A I& ?/ t8 S+ p5 _ h9 x: P; U
<P>the Delete method to delete the record, and the first user has already </P> " }; O4 R- j4 p! w<P>changed it, a run-time error occurs. </P> ! s6 ~0 ?, E+ C% D0 a; n<P> </P> - v' [ |2 k g: F<P>Typically, if the user gets this error while updating a record, your code </P>% ^5 c" L/ p0 `; }5 T
<P>should refresh the contents of the fields and retrieve the newly modified </P>/ N9 _. e* h& W7 M2 v) ?* Q
<P>values. If the error occurs while deleting a record, your code could display </P> ( F4 |3 m$ G. N1 O# |( v3 J, N6 N<P>the new record data to the user and a message indicating that the data has </P> . ~: Z% u! H. K$ L3 H<P>recently changed. At this point, your code can request a confirmation that </P>" l) m# z) }, L2 v, h3 e: h; @
<P>the user still wants to delete the record. </P>+ `. K3 ] }' w0 F, y
<P> </P> . [1 N6 R9 T8 l<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> 7 u8 u) s' h6 r( f. B<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>2 M# b3 ]! z7 L
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> * t% `. [) x: }; [: K<P> </P>9 e0 w+ q1 W2 n: g9 D" p) a
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> 1 s% k) E6 e2 a; [' r# ]<P>the dbRunAsync constant in the options argument. This allows your application </P> 6 ^+ K" G8 P- S% ]/ Q; ~) I<P>to continue processing other statements while the query runs in the </P> ) Z( [ Q! |0 u+ }5 P<P>background. But, you cannot access the Recordset data until the query has </P> 4 \) M( Y# }' O5 f, Y! u# h<P>completed. To determine whether the query has finished executing, check the </P> 3 t' }' _( i& R0 W9 T9 F<P>StillExecuting property of the new Recordset. If the query takes longer to </P>+ f, a" S' U7 a' c. k8 k' M& l
<P>complete than you anticipated, you can terminate execution of the query with </P>( m2 M+ N9 T8 w
<P>the Cancel method. </P>: w# S. \- [1 L7 p. i
<P> </P>5 j% S) r2 E2 U8 a: N
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> ( p5 v) F3 a7 f( y- J<P>connection is busy with a prior </P> ; \: P! ~! e0 v. [4 e7 a b<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>; a. R4 o: l. O8 v8 ?5 z4 w
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>) u4 a# w6 z" D& u4 _9 i9 i- W) f
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> , l G8 q/ q# Q<P>is opened. </P> ]$ c# p1 q" ]/ H<P> </P> ' ^7 d3 Z- o, Q- T3 Y u<P>If you open a Connection object with DefaultCursorDriver set to </P>: \3 R! g3 \! \
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>2 I' n# e! |8 J! U& B2 b! ?
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>8 a% D, S* [; U8 _# C
<P>h in the lockedits argument to enable update caching. See the Update method </P>0 G; |- O5 ?# E) d
<P>topic for details about how to write changes to disk immediately, or to cache </P>1 {2 \/ [; F0 P$ C) f
<P>changes and write them to disk as a batch. </P>( q% T6 B# t# O" ]$ h& e
<P> </P>, ?7 U$ w2 `! T( X+ [" |
<P>Closing a Recordset with the Close method automatically deletes it from the </P> 0 R [' a" E6 T4 R7 p5 o ; Q9 P0 \+ b- Z9 `5 Q9 j9 Z<P>Recordsets collection. </P>- {- H, V% \ e# U. m) p. W2 k
<P> </P>2 Z- ~3 Q$ R9 v9 |" ?! t e8 g
<P>Note If source refers to an SQL statement composed of a string concatenated </P>% z7 ^5 L$ M! e V5 [/ ]- |
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>5 ]) g& b- g% r( H& _
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> , o. \ R) {# F) X<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>! W' @3 \2 G9 j: c5 y$ d
<P>Recordset. This is because during concatenation, the number will be converted </P> 0 F0 A; S1 ?6 T A9 ?7 D<P>to a string using your system's default decimal character, and SQL only </P> 1 |$ \9 Z2 v+ A" |& P<P>accepts U.S. decimal characters.</P>