<> </P> , U# Y5 t7 v3 ^/ C M8 ]<>Creates a new Recordset object and appends it to the Recordsets collection. </P> 9 g# z7 T) P: T) \- d: ?<> </P>8 u- w6 k! D; R# _5 a& H* G+ W
<>Syntax </P> 2 {" K, O& |7 g, h9 j<> </P> : x) b" L* Y" {% Q; A' ?- s& b0 D, x<>For Connection and Database objects: </P> 5 v; f$ a7 j) W<> </P>! J; n8 F4 k6 O" x5 e
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> * E0 I* L% W; }' w& j<> </P>3 G8 N3 j3 V+ V/ }
<>For QueryDef, Recordset, and TableDef objects: </P>, N' ?( _: |7 W- ^# I+ z2 D
<> </P> - Y g. M( O6 w+ O<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> . [: Z2 k/ {) z1 T4 h$ ^ _" i<> </P>0 F5 H& U5 O6 ]0 R4 H
<>The OpenRecordset method syntax has these parts. </P> , G b3 m; r0 {. q# \' q$ H<> </P> $ t4 h/ r9 \2 g<>art Description </P> ! Q5 F- I' A2 w8 m2 F<>recordset An object variable that represents the Recordset object you wantt to </P>% ^5 a" |1 O( {
<>open. </P> $ x/ J' t) Y( ?5 x J; n<>object An object variable that represents an existing object from which you </P>0 F8 K: p( u9 Z% d
<>want to create the new Recordset. </P> H& o4 r8 T# u: `* B5 M<>source A String specifying the source of the records for the new Recordset. </P>. l7 `$ E8 k% D" p1 |; s% ]
<>The source can be a table name, a query name, or an SQL statement that </P>, t1 M. f0 E" S$ t, D+ _/ p( ~: f
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P># M" x4 A4 ^# [+ Q. i
<>the source can only be a table name. </P>$ @! T5 P) }- _' v# G9 r) s
<>type Optional. A constant that indicates the type of Recordset to open, as </P>( C. ~, h2 s( h/ K* Y4 ]! x; U
<>specified in Settings. </P>0 F! k* X0 l/ ~! U
<>options Optional. A combination of constants that specify characteristics of </P>4 u1 x R* s" o: ^$ U7 M
<>the new Recordset, as listed in Settings. </P>2 K$ V: s% `: H/ H. P
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> 3 C: [1 L( ?+ n, k" d4 p<P>as specified in Settings. </P>' K0 I" ?$ ?% a/ G# @
<P>Settings </P>8 t3 g2 d5 }) D9 L2 p
<P> </P>' H, U; {3 y+ ]4 P, \
<P>You can use one of the following constants for the type argument. </P># L, g# e9 D+ R# v* t) Y# ?0 x
<P> </P>& }7 V t5 F7 p! `
<P>Constant Description </P>. o5 t9 K' Y) m9 f
<P> </P> & ~7 V! `, R. u) ^5 `7 T<P> </P>6 N$ f, p+ [9 C8 W H" n- `6 l
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> ( C2 N% T* `( J' }<P>only). </P> 5 i5 K! n! V6 I1 F- p6 @0 ]" ?2 `6 u<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>' j2 d- i. Q/ P$ J' j3 j# Q
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> ' J6 T0 o& j* q' ]" D" g7 p<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P>6 T; Z$ ^0 {3 C3 s
<P>ODBC keyset cursor. </P>3 g4 }/ C/ _+ j7 }6 ~, i$ Q) s
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>$ f& H$ I# V7 [( e" ^
<P>ODBC static cursor. </P> , g4 C7 c5 f( d; }" q<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>$ n! y4 O* O* o$ A- c$ |
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>( ~' K- l' q+ P4 Q1 R/ f o
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> 0 ~! q8 W: g9 m N R9 ?<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>2 Z0 [3 N0 J- h7 _( i
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>- o8 H0 p/ H& A( c a
<P>y. </P> 2 b) u! E8 ?8 F* f0 e" L<P> </P> # _- T2 A; i$ c2 Y" T2 N<P>You can use a combination of the following constants for the options </P> ! J; d) C1 _9 I+ U0 _$ i1 o<P>argument. </P>* T( T: N! W" f
<P> </P> 9 ^5 X4 \, `( g0 u# H/ y9 X<P>Constant Description </P> ' E; }3 H/ u& P- O8 d<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>1 ]. j* p* Z" i- {) p. j( H
<P>prevents them from editing or deleting existing records (Microsoft Jet </P> 0 f9 M* g: u% } I. X<P>dynaset-type Recordset only). </P> ) E5 I; [2 o6 ?/ [# V<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> / S' g6 h5 ? Q& W, Y<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> ! X# {% _' c7 D7 V1 X<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> 0 |( |" _+ R, J$ s2 c& T( n% q; ^<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> ; X$ p% Z. N% P; M$ w<P>useful in applications where multiple users have simultaneous read/write </P>8 Q+ C- n' `! p
<P>access to the same data. </P> ' U, \6 w* M. [5 t4 E2 ?0 l) j" G<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>0 F" Z) x* D8 w; d
<P>Jet Recordset objects only). </P>0 K& e" l* m- U9 X" @# m
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>! V; d- j+ X! W; \; K) V
<P>table-type Recordset only). </P>& d8 ?1 w6 |3 ]2 @9 S9 S2 z9 j$ Y
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> : l) \" m3 |5 Z9 [<P>Recordset only). It is provided only for backward compatibility, and you </P> - f$ A; _+ T4 C- a- v<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>" V4 f. k8 g- D) q- V4 m
<P>using this option. </P>+ ?0 W w, v6 l- [5 V; ?
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> 6 @1 p7 D8 K) j2 v9 N8 ^<P>only). The dbReadOnly constant in the lockedits argument replaces this </P> , y/ B* }: [, F: I5 Z8 D5 k<P>option, which is provided only for backward compatibility. </P>0 {1 r; i5 j: v" \) z' t) p
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P> 6 R9 r; ?" V7 J! N8 P<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> ) L! F3 H \/ r% A( c<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>+ r. ~" T: @0 {6 y
<P>not opening a Recordset based on a parameter query. For more information, see </P> 0 ], W# a) P* w m<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>1 ^ F" A, D5 Z
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> ) ^' u5 V) ]8 M7 {' l6 w6 |' g. s<P>snapshot-type Recordset objects only). </P> : }2 u5 F- N' \2 ^, A<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> ; m% [3 J3 b4 G0 `' Y<P>snapshot-type Recordset objects only). </P>" x6 e1 s' o7 @- ]! y( z, s: [# k
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P>5 M* R) Q8 ^# U! n; I* R. B
<P>and using both causes an error. Supplying a lockedits argument when options </P>0 r" ^" Q) n6 B0 |4 B: k/ R
<P>uses the dbReadOnly constant also causes an error. </P> R& F o# j" `/ V, | t
<P> </P> + O! T2 w" y' D) ^; l* g<P>You can use the following constants for the lockedits argument. </P>4 M9 G9 s$ j: ~* x8 k
<P> </P> x9 b+ v% ? m5 V9 m' v) p7 n
<P>Constant Description </P>* i0 `! L" ~1 T. L$ }# O
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>6 z- z3 m. P- V% _$ \7 i3 g: F
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>) B# G, B9 D5 b- `
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> " c. `8 \0 c. I& t" ^<P>run-time error occurs. </P> + k' z1 P+ z- L6 X+ y. f9 E<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>( r* s) Y7 m; R! t( o1 ^1 F( E
<P>the Recordset in a multiuser environment. The page containing the record </P> w) n9 `( d! s, l<P>you're editing is locked as soon as you use the Edit method (default for </P>3 H) V+ I( ?* N. v- v, _3 S7 b* c
<P>Microsoft Jet workspaces). </P> 7 }% E8 l! J$ c3 u% _<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> - C! T9 m9 [7 Z# k: o' B<P>Recordset in a multiuser environment. The page containing the record is not </P> ; F9 C4 M' y5 H: d W<P>locked until the Update method is executed. </P> $ K( O9 r& q+ K" _, V: y' o<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> n& ]; G! q' V& K! C8 d
<P>workspaces only). </P> + X1 O) {+ h; U, l<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>2 P( t0 \( B; }
<P>only). </P> + m5 G1 i. c( n1 I( {9 P B3 I<P>Remarks </P>" \( C- B3 D, J
<P> </P> 0 U. k! ^! w8 u3 Q<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>0 c3 b5 m: q: b5 y1 o- F
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> % ? `8 h5 H1 z( [8 l9 N<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> % T( B( u( t( U* E! i9 F<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>, K$ [+ F* c5 v
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> . @! a# x. \2 H<P>data source, you must first set the Connect property of the linked table's </P>2 @6 J1 X' j4 {% R' b' V' I6 U
<P>database to a valid ODBC connection string. If you only need to make a single </P>* K: g8 K$ D7 _- _
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> . H# j7 J& I/ C' V" a$ t<P>source, you can improve performance by using dbOpenForwardOnly for the type </P> * F: q# R K8 z- q) i/ Q<P>argument. </P>- E$ }$ H& f1 g: ~% f
<P> </P>9 \3 T) k# n8 X$ S0 c- d# i: Y
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>; j( @9 m1 m: x! ? r
<P>is of the same type object. If object </P>1 |) a6 r9 t( A
<P> refers to a table-type Recordset object, the type of the new object is a </P> - r f. E$ M% n, E, F9 V<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> 9 m* J: _) [+ y8 j9 m9 C3 `<P>杢ype or ODBCDirect Recordset objects. </P>$ `& m1 Q" @2 l; ~; F i
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>% z( h' v+ }& P* S* q+ m8 W
<P>select query in the source argument, such as </P>) v5 p+ H2 |6 W; I* L3 a/ z
<P> </P> 6 q2 S, ?3 T# _4 w* y( I4 E3 ^- T<P>"SELECT LastName, FirstName FROM Authors </P> * | \' V: I5 f, G( A6 l<P>WHERE LastName = 'Smith'; </P>2 I% @- F9 K/ g4 n7 l$ M8 B
<P>SELECT Title, ISBN FROM Titles </P>7 J% a. `; j8 C e4 M* P) o
<P>WHERE ISBN Like '1-55615-*'" </P> 4 d* u. k5 z, F: H<P> </P> ) o- f1 x: M3 S& Q<P>The returned Recordset will open with the results of the first query. To </P> ( l* I9 H: ^+ C) B1 _4 G<P>obtain the result sets of records from subsequent queries, use the </P> # _# G% q) L7 n" e" F<P>NextRecordset method. </P> : y& r% X7 s' t<P> </P>, C0 E2 Q5 W! a1 t1 ]7 P J
<P>Note You can send DAO queries to a variety of different database servers </P>$ o0 E( i/ R/ g! z
<P>with ODBCDirect, and different servers will recognize slightly different </P>, O9 p- w2 ?9 b+ ?0 ]
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>9 T: r, b; k. X; y
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>6 Y& D4 V) u' L/ e* e4 J) B4 R" Z
<P>included through the Help menu. Be sure to check the appropriate reference </P> # P2 L1 H) S/ r<P>documentation for the SQL dialect of your database server when using either </P> C8 E [% E& I<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>7 Y/ I1 f# c3 k' C( S9 _
<P>client/server applications. </P>- D7 j9 M7 S# G: f2 n
<P> </P>! U+ x% y) _- t
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>2 v0 H7 I) k' h
<P>trap changes while two or more users are editing or deleting the same record. </P>2 n* A7 @( s4 _
<P>For example, if two users start editing the same record, the first user to </P> ; p8 f; p. r5 Z" v8 {3 B<P>execute the Update method succeeds. When the second user invokes the Update </P> ( j0 L% A4 k) I! { u+ Q<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>" d0 L5 U+ Y) R& \8 c; w
<P>the Delete method to delete the record, and the first user has already </P> . d% A) w6 E' I$ ?; D3 p$ O9 {# V" j<P>changed it, a run-time error occurs. </P> 3 A' b$ E* e! X: T- N<P> </P>( o. h$ i: A& I6 C; X
<P>Typically, if the user gets this error while updating a record, your code </P>! k# Z7 [4 i8 \: E( ]; Q) [- I% Y. I
<P>should refresh the contents of the fields and retrieve the newly modified </P>5 s/ e& o; C% g- J4 ^
<P>values. If the error occurs while deleting a record, your code could display </P>3 G- }3 s& g1 [- t) {: Q
<P>the new record data to the user and a message indicating that the data has </P>- |* x. Q* \: t( R0 \
<P>recently changed. At this point, your code can request a confirmation that </P> ; D5 R: a$ I6 } b5 C<P>the user still wants to delete the record. </P>2 i( @, ~# t" T i) A! v/ q% q
<P> </P> 9 k! Q, |+ V6 |- l6 l7 U1 f<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> - Y* Q$ @1 h5 K" z<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P> 3 b2 `0 u; j+ `( J9 @. n<P>later) table that has an IDENTITY column, otherwise an error may result. </P> 2 c N/ G; V! ` w<P> </P>( K ?9 U# z6 o- O- \2 t1 r2 O
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> ; @3 N0 p7 L I' m9 Y<P>the dbRunAsync constant in the options argument. This allows your application </P> - k+ U4 ]; `& u$ [5 e<P>to continue processing other statements while the query runs in the </P>/ V! v' a; O. }: Q
<P>background. But, you cannot access the Recordset data until the query has </P>/ z/ d) l* T/ W. R& W
<P>completed. To determine whether the query has finished executing, check the </P>, m$ g; s$ f& S: J: o: g% A
<P>StillExecuting property of the new Recordset. If the query takes longer to </P> & n7 i/ W0 ] I) _: U* L<P>complete than you anticipated, you can terminate execution of the query with </P> 2 O, \/ ^+ @6 e0 x' O4 Z0 P/ @+ d<P>the Cancel method. </P> 2 G4 U1 Z% r2 y/ |2 x ?/ N<P> </P># l1 r; r* w: S
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> & t; j) x n3 t( d# h4 O<P>connection is busy with a prior </P>& H5 N) c4 w' M* s% q
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> 0 K- M W) T$ {" F z<P>ODBCDirect, if the server supports this. Another solution is to fully </P>) C, V# N4 U+ A2 Y+ c) |
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> & E: j* Z* U h( k& q1 m7 N* Z<P>is opened. </P>7 P- g1 X `% a& m D
<P> </P># m* P/ w4 F a0 l5 P
<P>If you open a Connection object with DefaultCursorDriver set to </P> 1 t3 K: ?/ `4 ]<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> * z3 N, F5 T) n/ {/ R$ z7 z3 x) v$ _<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>& |8 Q! ]" |4 ^% F! K. C% `% i
<P>h in the lockedits argument to enable update caching. See the Update method </P> * H o' z6 `% Y/ @% @/ t9 e<P>topic for details about how to write changes to disk immediately, or to cache </P> & N3 n1 ~# S8 ]0 R, l<P>changes and write them to disk as a batch. </P> ; k: a6 B! ]1 O2 i8 n) b<P> </P> 3 h1 g1 q* O8 f' `: s0 I: ^, V! b<P>Closing a Recordset with the Close method automatically deletes it from the </P> 8 t3 @0 E- h3 {* ]( o' b! U! o2 F% l: l4 T
<P>Recordsets collection. </P>( q0 X K1 }# u) u
<P> </P>1 ^& W' S; q! m$ L! ]2 }5 l- B& j
<P>Note If source refers to an SQL statement composed of a string concatenated </P> $ m5 ^/ g7 D' a8 F2 a! A; ^4 |<P>with a non-integer value, and the system parameters specify a non-U.S. </P>5 |" v1 A! B) ^ [$ E
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> 8 Q( Y0 }+ P5 Z2 r6 U/ O<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>/ F$ E% Q% S) `4 d3 W' L# y
<P>Recordset. This is because during concatenation, the number will be converted </P> + T- l# S8 d9 F) M0 _! k$ [2 a! ]<P>to a string using your system's default decimal character, and SQL only </P>) U: W# T# q& C5 a: w' ~! {
<P>accepts U.S. decimal characters.</P>