<> </P>/ i+ a; I" t1 q
<>Creates a new Recordset object and appends it to the Recordsets collection. </P> : m0 N4 Q# i6 W<> </P>$ V4 j( g( e$ ~+ O: N% ~
<>Syntax </P> 5 ~, u. V1 J; B3 Q m3 H4 N: M1 l# H<> </P>6 l# U& u! P- d3 y. a; M' H3 {
<>For Connection and Database objects: </P> 3 a2 `) b- Z8 u$ J) l* G<> </P> $ M! A E i, h/ ~% \5 \<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> + g4 \# P$ X, W% C<> </P> 8 T4 Z- h2 y( x6 J8 o2 F<>For QueryDef, Recordset, and TableDef objects: </P>/ i5 M& I1 s/ P
<> </P>( l( u% \' ~ X$ U
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>. j1 m1 Z# ], E" d2 L) G
<> </P> ) S* \9 P3 [4 f k& P* D6 @<>The OpenRecordset method syntax has these parts. </P>; k% M" V, @/ b. s7 O) O8 i# @# Q7 X
<> </P> 9 E5 Q+ \' h5 v& Z2 E7 B* Z: [<>art Description </P> 4 R/ F% u: b2 m9 V2 x, L<>recordset An object variable that represents the Recordset object you wantt to </P> - @0 `* \6 \/ u6 k( f<>open. </P> " |6 ?+ E3 Z, {3 b<>object An object variable that represents an existing object from which you </P>" E8 l5 m/ x; L9 O& O s9 \
<>want to create the new Recordset. </P> ( S; m# y3 A2 f/ {+ g<>source A String specifying the source of the records for the new Recordset. </P>( r' D, C8 }9 z
<>The source can be a table name, a query name, or an SQL statement that </P>: m+ E* t4 v; m1 W/ m7 R" B/ E) p
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>; m+ Z# b% ~" _2 r8 p' F
<>the source can only be a table name. </P>- }. ?6 H. |# z3 e% J
<>type Optional. A constant that indicates the type of Recordset to open, as </P>% f( J7 i& M: i; z* V+ `1 Y
<>specified in Settings. </P> 0 ^5 k6 h0 w" w8 x O( X6 p' X<>options Optional. A combination of constants that specify characteristics of </P>' ]+ ?5 h1 \8 }, S2 \8 k* d
<>the new Recordset, as listed in Settings. </P>5 |5 @) W8 j5 M8 e% a( L2 U+ K3 W+ \" z
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> $ ?6 T- l/ [5 q<P>as specified in Settings. </P> i% c" S5 K3 t. N<P>Settings </P> 1 _7 P [$ R; W<P> </P>( d& b* `4 g M( d
<P>You can use one of the following constants for the type argument. </P> 4 X' ]+ g: @5 U- H- s$ k4 r<P> </P>6 } y" S. f: K& U% x3 v
<P>Constant Description </P>0 \. M! `. E! @" r2 c: Z& U/ ]
<P> </P> b3 H t) Y5 b ]$ _, V& }
<P> </P>0 V$ L. V' u9 ?+ Z7 X% l1 ` g7 ?
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> ) P1 s/ q l6 ^! }, a8 |$ l' b<P>only). </P>7 M/ ~9 O2 V' Q) G. J# J
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P> / y. V1 I3 Z- ~* U% |, D<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> : i9 S' n! d& T- Q' O p<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> $ X J; [& B. j n. S% m, o<P>ODBC keyset cursor. </P>; S- @8 c( y$ Y1 U. ~
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>( Q8 E) f* s& T0 E; ~* F/ H6 e5 f
<P>ODBC static cursor. </P>& W) ~/ d" T/ {6 a& n( j) L
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>0 w5 F) h3 l( C- ~
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>; f' m# |6 u5 e8 j w
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>. d7 F4 b5 J n8 U0 w7 r
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>1 V' p& Z" y, H& D7 |1 z. r
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>8 C/ H* m, I5 k& f, s
<P>y. </P> * W- J9 n' T5 O. I$ X3 m& G( O: _/ b<P> </P>9 S3 N8 o( {) _7 m* [, R) a0 R
<P>You can use a combination of the following constants for the options </P>! u3 [2 G; t# b# @/ I7 e; k
<P>argument. </P>* y3 j. N+ W- N2 h, K( b
<P> </P>3 x' t4 @' ~+ @
<P>Constant Description </P>- _ n0 h! z# f3 s. i4 z
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>7 C# `) v- k2 d2 v* [& u$ Q5 p
<P>prevents them from editing or deleting existing records (Microsoft Jet </P> 7 }! s( b1 F8 [2 Y6 f# o3 E0 S<P>dynaset-type Recordset only). </P> . ^3 H$ K& u' f1 {4 N) B<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P># \7 k, D1 o0 _( G* F
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> 2 G2 |$ N" {+ a5 {/ R0 e<P>dbSeeChanges Generates a run-time error if one user is changing data that </P>9 t6 I2 e( I; ?9 S" U$ C( I
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> & e' h l( n7 k<P>useful in applications where multiple users have simultaneous read/write </P> ) Y# z$ b$ { i C4 [4 t- o<P>access to the same data. </P> $ \; M. @) w+ I; \3 W* _<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>4 m& r. x" p& Y8 n5 J; }4 B
<P>Jet Recordset objects only). </P> . z- K/ J4 Z, M9 }<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> ! }2 O- k# g( o) L. O- J. e<P>table-type Recordset only). </P>3 J$ S) T( a3 e
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>+ g7 A+ `8 I8 S
<P>Recordset only). It is provided only for backward compatibility, and you </P> : P- w, `: E. {7 l: F, x4 j; ?4 O<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>/ } _ n8 g/ |
<P>using this option. </P>/ U5 {6 Q0 D$ o! s
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> " A% P: e2 o" Z7 n0 f: ?7 q. u<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>3 _, {* I/ a! E3 P. H/ u$ v
<P>option, which is provided only for backward compatibility. </P> * t m* p( c1 g; Z/ c1 }<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>2 @5 k2 P$ b2 s v# s0 T
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> 7 ~6 w1 U/ d2 X+ m& H/ x" _<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> , a/ t, t8 W( l) J<P>not opening a Recordset based on a parameter query. For more information, see </P> ) l( z% L2 K4 N# G<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>% y8 u2 V" V) m
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P># }' c& A" y' L
<P>snapshot-type Recordset objects only). </P> ( i+ e$ }- ?9 a6 [3 t( ]<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> ) r ?7 o5 A/ W/ Q8 i<P>snapshot-type Recordset objects only). </P>5 Q) [ ~& A/ k% x
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> * ~2 L/ x6 e. \6 D. }- z<P>and using both causes an error. Supplying a lockedits argument when options </P> # G8 {( E: f, q' J& x5 x<P>uses the dbReadOnly constant also causes an error. </P> ' r, y$ }, @( Z, w" [5 C<P> </P>8 x8 I% y# v9 ]7 Y
<P>You can use the following constants for the lockedits argument. </P> ( S j: W: z3 p' z+ L+ {9 |+ g3 H<P> </P>! Y9 O+ `5 a. e; q
<P>Constant Description </P> 2 F- ^. d' [4 Z+ q5 g: J<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> % j; a3 x5 A: Y9 ^9 k<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>3 c- @7 f+ ]5 L4 W- ^- B' B
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> H* R3 P, v T: J<P>run-time error occurs. </P> r7 r. ]% G' c1 J: a( K1 {% V1 k& _
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>1 l3 Z9 |2 x( ~* B7 v4 T
<P>the Recordset in a multiuser environment. The page containing the record </P>& |" x" X/ t$ Z& q* E( J
<P>you're editing is locked as soon as you use the Edit method (default for </P>) r" W5 E* K, W4 i" S) l
<P>Microsoft Jet workspaces). </P>7 l8 v5 Z, X+ Z9 J2 s+ F" }
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>+ v) o/ k; m A9 M4 _4 O$ W% G
<P>Recordset in a multiuser environment. The page containing the record is not </P> $ i8 n3 I. R. x7 h# `<P>locked until the Update method is executed. </P>+ P2 k8 o% R; v- v# J! s
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> ) ~/ }( g+ m9 j7 p5 h. `<P>workspaces only). </P>" @0 F( V- ?' o2 k+ t" ~" I* k! `
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> , e1 w# w3 l8 }6 Y9 c( H# v5 P<P>only). </P> * e( W- w) o, {+ c<P>Remarks </P>& u2 T# i* C! ^/ W W
<P> </P>7 N/ ?8 z2 i; P- v. q
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> 6 g9 P' {$ F' v<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>5 C4 f/ L2 h* |. w) f' \" R
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>2 S- F- a x# } H4 I
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P> 5 d6 m3 P8 f6 f. V" \3 `<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> * r% F( N% `" E<P>data source, you must first set the Connect property of the linked table's </P> + S: G% g" V) K" g<P>database to a valid ODBC connection string. If you only need to make a single </P> `4 g1 }6 H* J8 @- S5 G: i
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> 7 `1 L( v# {2 N4 L# T<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>! d& y9 P$ }4 _8 C. c
<P>argument. </P> ( |2 D# R# I* u; R$ ]* y8 @0 I<P> </P> , Z6 o6 y* w- [1 a* J) _3 B<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> , Z4 z5 x* i- v<P>is of the same type object. If object </P> ( H- P! G' G# p3 b4 m p<P> refers to a table-type Recordset object, the type of the new object is a </P> 3 t ]" w5 l: v( g( s! O<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> 8 l; m6 ]! ^% I5 U, U( Q) ?<P>杢ype or ODBCDirect Recordset objects. </P> / Q1 Y j4 j: e7 P( C) x<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>2 c2 U0 l$ W4 b, l: U: [$ v& B+ i, I
<P>select query in the source argument, such as </P>5 U. `+ @) Z$ |: u
<P> </P>( t+ I! Q/ m( n9 D7 b9 z0 y9 N1 Q
<P>"SELECT LastName, FirstName FROM Authors </P>4 @& j4 j' G8 K& f# k0 v7 T+ P! U
<P>WHERE LastName = 'Smith'; </P># p8 X' w; o# _1 l. I2 ~% X. q
<P>SELECT Title, ISBN FROM Titles </P> 1 _; C7 Y; g8 p/ k6 p<P>WHERE ISBN Like '1-55615-*'" </P> ; Z, R7 n* K" W) Q/ S<P> </P>! L1 C* l) f$ K7 |; `
<P>The returned Recordset will open with the results of the first query. To </P> % |+ G* M! f7 I) \ u) ?8 d<P>obtain the result sets of records from subsequent queries, use the </P>' B/ ^0 I, B7 {' E% u1 Q$ l
<P>NextRecordset method. </P>1 i6 W( G3 _* u9 r# }# k6 p* I
<P> </P> ) n) v4 M( h/ x/ a8 |( c<P>Note You can send DAO queries to a variety of different database servers </P> ' Q9 Q0 ^) J y# a<P>with ODBCDirect, and different servers will recognize slightly different </P>8 i! W: R( L; e' ` T
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> - i- U& c% B# w; u, i7 t$ S<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> . Q8 h. |1 B1 H) X8 J<P>included through the Help menu. Be sure to check the appropriate reference </P> 6 Y" O/ k, U S' e<P>documentation for the SQL dialect of your database server when using either </P> ! Z. h' R, p, E# M<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> + F P" c3 {5 b- r+ t A<P>client/server applications. </P>2 b% Z8 S% Y/ p* X
<P> </P>1 Q6 s% P" \! _5 W8 \
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>5 s3 m" l6 K8 h7 W( @
<P>trap changes while two or more users are editing or deleting the same record. </P> " J& A+ U+ i. m9 }8 i<P>For example, if two users start editing the same record, the first user to </P>2 M. e& D6 K' |$ f+ b
<P>execute the Update method succeeds. When the second user invokes the Update </P> : c2 S- c" C. }# K0 `8 d4 ~<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> / V- f) p. @" `/ @8 I+ c<P>the Delete method to delete the record, and the first user has already </P>2 h6 n e! i7 Q/ v, M
<P>changed it, a run-time error occurs. </P> * M+ D( d# B& _7 Y0 q/ s: @7 l<P> </P>1 F+ Z& T* h) E. n
<P>Typically, if the user gets this error while updating a record, your code </P> 0 T8 m# \9 V% G R<P>should refresh the contents of the fields and retrieve the newly modified </P> 4 \3 m7 p" T; [3 `# R$ }<P>values. If the error occurs while deleting a record, your code could display </P>, F0 \$ b5 Z4 x2 H$ x! @
<P>the new record data to the user and a message indicating that the data has </P> " S0 v6 `9 M( I( ^* I# h* {' p a<P>recently changed. At this point, your code can request a confirmation that </P>/ L9 I% [1 u3 a, B6 n# O% t
<P>the user still wants to delete the record. </P>: P( M; a' [5 d, e3 H1 n: _+ l5 \
<P> </P> - u. D. F; A1 C7 A<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> 0 A6 Z7 ^$ Q' g<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>* B0 A2 Y3 ?. R5 P9 K5 E
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>' t) r+ M, |' N7 v5 D
<P> </P> * e/ I9 A+ u: q" b& l/ l! ?# }0 U<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> : m! t, ^1 l9 o" ^* {% ~- T<P>the dbRunAsync constant in the options argument. This allows your application </P> ( w0 B4 N# x* r4 B<P>to continue processing other statements while the query runs in the </P> * t/ Y. P1 q; T" A' @<P>background. But, you cannot access the Recordset data until the query has </P> 4 m+ h2 o9 g$ a- a8 j8 H<P>completed. To determine whether the query has finished executing, check the </P> , L4 d& r( `0 _; D, m! V<P>StillExecuting property of the new Recordset. If the query takes longer to </P> ^4 A8 _' e5 D" x5 l3 x<P>complete than you anticipated, you can terminate execution of the query with </P> 6 }! }6 @% V9 m2 ~<P>the Cancel method. </P>! a2 c7 B: I6 K( }' U& X9 X
<P> </P>1 Z: G) i6 n4 `3 O7 K$ z% y
<P>Opening more than one Recordset on an ODBC data source may fail because the </P>- D: z( l$ z; L! ?* T3 g
<P>connection is busy with a prior </P>. V/ ?( M5 t0 h" V, W% A
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> - Q* B8 a1 R& p% U7 l<P>ODBCDirect, if the server supports this. Another solution is to fully </P>0 [7 T! T2 M0 ]9 `* R
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>8 m1 Q% v |2 ~$ m- @" S
<P>is opened. </P> " a* b( L6 a( b4 l) m<P> </P>8 y6 f9 X9 h! G% `; D1 Z
<P>If you open a Connection object with DefaultCursorDriver set to </P>8 \5 I+ c8 o+ E! R' K2 T4 k. h' Z
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>+ H# R- G* d/ N$ t2 f$ h0 \/ e
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P> 9 x0 ]+ e3 c9 }1 r<P>h in the lockedits argument to enable update caching. See the Update method </P> 5 x' Q4 v3 [8 \<P>topic for details about how to write changes to disk immediately, or to cache </P>4 Q) q/ G( ]/ l# t/ |
<P>changes and write them to disk as a batch. </P> ) L# L. r7 C2 \ f- U& Z<P> </P> 1 B1 e' a: e3 Y3 Q% B+ e<P>Closing a Recordset with the Close method automatically deletes it from the </P>2 P$ r" M1 ?5 S4 M6 B& k
6 _7 l, @1 T% K9 E2 h<P>Recordsets collection. </P>- }. \- z) w- Q3 {8 t8 m5 y
<P> </P>0 _( f3 T: ~2 s; |" R g
<P>Note If source refers to an SQL statement composed of a string concatenated </P> 2 ~" ]8 t0 o8 n. [# e3 n8 b<P>with a non-integer value, and the system parameters specify a non-U.S. </P> ; W7 g4 _5 O6 E<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> / T/ o5 V ^9 Q4 ]; M5 v& o<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>7 l) ~& A9 Q' F- K7 P$ P. I
<P>Recordset. This is because during concatenation, the number will be converted </P>9 P) L2 z" o- ~3 l0 m7 A& C& m
<P>to a string using your system's default decimal character, and SQL only </P> " Y T8 J% x' J: c9 }<P>accepts U.S. decimal characters.</P>