<> </P> ; F$ V- _. o6 k3 I5 G7 d8 c<>Creates a new Recordset object and appends it to the Recordsets collection. </P> 0 {6 D4 ~/ N* `& O4 j<> </P>& D3 E7 \3 `% X1 I! D0 R% G
<>Syntax </P>/ p$ k. i9 \5 ~: R
<> </P>/ }/ e) `! {+ U7 i; W: I& Q
<>For Connection and Database objects: </P>+ i% K; D+ h5 Q- H. _7 J. r% |4 M
<> </P>- {0 r; S$ M4 I9 x8 s: m% t( w
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>2 q7 |9 k. j5 ]/ |8 f' s& \
<> </P>+ g1 ?, U) j. K
<>For QueryDef, Recordset, and TableDef objects: </P> % S4 b$ t$ M6 U9 P# Q$ w5 M& C6 f" Z1 m( M<> </P>+ X5 X. C2 h, u* e$ R9 |
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> A+ L9 ]) ?- B6 L- D2 v: l' j
<> </P> 0 _/ R5 U, v* F, ?; l<>The OpenRecordset method syntax has these parts. </P> ) k+ k8 o8 p/ Q2 J% ^1 A H+ u8 Z2 h<> </P> 8 R+ j7 }) g8 u, s<>art Description </P>+ S5 F7 o) \ k o) T4 e0 ]
<>recordset An object variable that represents the Recordset object you wantt to </P>" D, E% R# Q7 U1 u6 p9 V
<>open. </P> 6 h6 Y( E$ ~+ i. J<>object An object variable that represents an existing object from which you </P>/ n3 U0 [; X5 h
<>want to create the new Recordset. </P> - d' q5 J/ W* ]2 e. o* {<>source A String specifying the source of the records for the new Recordset. </P> 7 ]8 D" R H, g n; k; n4 I<>The source can be a table name, a query name, or an SQL statement that </P> + X! ?& r# S& ^" {+ E( c; s<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> 8 ^5 r) z$ \; _+ P<>the source can only be a table name. </P>; _9 O7 E& H) X9 _
<>type Optional. A constant that indicates the type of Recordset to open, as </P> 9 V- T6 Y+ j/ O( i. z* S" _% q7 n<>specified in Settings. </P>8 h: [, j8 H, R6 j0 E
<>options Optional. A combination of constants that specify characteristics of </P> , M/ {& ^: A2 |% w* R; L. m<>the new Recordset, as listed in Settings. </P> 1 g8 h! V2 M4 L$ A) O0 m<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> + A# Y: e/ g6 ]' l4 i<P>as specified in Settings. </P>6 L, F- t8 r7 q2 U1 e0 x
<P>Settings </P> ; D' R, M+ _) s. x2 r3 Z$ z6 N<P> </P>9 V3 h3 E4 q1 E2 L
<P>You can use one of the following constants for the type argument. </P>7 z+ ^, m: S- U+ J& B; H
<P> </P> ' K* J+ M. @& i6 p/ c<P>Constant Description </P># u8 a6 I" |, X1 ~& U1 Z
<P> </P>1 m: E5 ]) p, X
<P> </P>6 K: n( ]- {" l) ^6 d
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> 1 D$ J" U4 q4 [8 L<P>only). </P>" K9 k; \- {8 F" `7 s7 e
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>+ ]/ A. k7 @7 N0 U
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> 5 _3 U' ?2 H5 J, a% F8 A, Z<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> ' R: V$ D' B- C+ ^% l<P>ODBC keyset cursor. </P> * D y$ ^ E9 j/ Z2 K# }1 D- N<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>- |/ r. s6 |9 s& B1 D
<P>ODBC static cursor. </P>' \8 y4 r5 G9 [1 s$ F5 X2 }
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P> ! o0 S. n2 B# w# V5 U<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> * V# q7 R. }, y+ P7 G2 v<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> % |2 d! _6 |/ c- _$ f' C<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>5 d% I- k5 p8 S) a. v
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P> $ i' l( ?7 P7 A; _* n8 O<P>y. </P> 9 E) c$ z# r% m- {<P> </P>; x& z7 W) Q- Q1 e h
<P>You can use a combination of the following constants for the options </P>* u- d& T$ w; a' }- Q
<P>argument. </P>: G. T2 a) z- v/ K* W
<P> </P>$ ]3 t3 l/ b6 R" A
<P>Constant Description </P>0 G3 ?& ` X! \/ A4 S9 ^
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> ; e& K9 q: B5 U<P>prevents them from editing or deleting existing records (Microsoft Jet </P> 9 l4 u6 L( L* p3 W3 V+ ]<P>dynaset-type Recordset only). </P>/ m" j2 s9 v+ f4 @% n( O
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> , r; h& Z4 \7 V8 h6 {<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>7 `" K4 i3 f- \ O& s7 v4 F
<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> ' R; @& G- c2 H: R; E1 t<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>! Y$ A' b1 s0 Q# g- T; R
<P>useful in applications where multiple users have simultaneous read/write </P> 6 K4 W: u" t7 c3 [! T+ l<P>access to the same data. </P>* k' H" L# u. ^2 U% p, {2 ]
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>0 ]. a$ t! T. E
<P>Jet Recordset objects only). </P>( c9 H C! u1 o- |6 m
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>" ^) v T1 `! |
<P>table-type Recordset only). </P>/ K4 I' N& W% B A8 h% U7 {
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> ; A4 ], k# ^+ ]' e1 @<P>Recordset only). It is provided only for backward compatibility, and you </P>, U( ^5 Y" U& V( \# ]' H
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>. z& S# \6 p; ?: Z
<P>using this option. </P> 7 U0 W, v l* d% p0 b: d<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> ; H9 H& V E$ H# ]! X2 v7 B |0 [. z<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>) P0 O- A. k) I3 }- v3 `! h
<P>option, which is provided only for backward compatibility. </P> ) _/ f0 r) y% ~4 K8 Q; b8 C<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>! Q8 M3 h/ K! R0 o
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>3 T& w7 W' H' |/ l& v4 y5 z
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> - U6 o; {! x4 _7 b z<P>not opening a Recordset based on a parameter query. For more information, see </P> # G! s8 c7 W. V7 ^4 _, c( O" L<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>" E/ T% E K. l* c% {5 P2 w; @
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> 9 q. z8 V7 A. y& {0 l: Y<P>snapshot-type Recordset objects only). </P> ( i& U- S6 S8 \0 t<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> + x {2 V! U, e( u<P>snapshot-type Recordset objects only). </P>! Y, Y/ L0 d$ H! X
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> " r0 \! ^* L) _! O+ n; t<P>and using both causes an error. Supplying a lockedits argument when options </P> ; t+ h2 b9 M# h' _) x" d0 D<P>uses the dbReadOnly constant also causes an error. </P> / L- _) H. i' v: ]& D6 r( c<P> </P> 6 r( d* _8 v5 G& l2 j<P>You can use the following constants for the lockedits argument. </P> ( n# {6 |# s4 v7 F" D<P> </P> 2 @3 b+ c: W% P0 `, i C3 E<P>Constant Description </P>9 @5 A% C0 n+ I! }9 P
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> + b* ]5 S" t0 s$ X/ N( O<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> 0 n; w+ T, _( w0 J0 c$ H<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>8 X' P! R% R! L8 H& d
<P>run-time error occurs. </P> D2 L; t/ I& k# |$ c
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> - f8 r& h) x7 P5 m<P>the Recordset in a multiuser environment. The page containing the record </P> & W5 X) G; H# j$ U( ~' x; d# F; |) L( y<P>you're editing is locked as soon as you use the Edit method (default for </P> 8 a7 p m. X! A# U/ T; v<P>Microsoft Jet workspaces). </P> R2 f2 y/ B- G9 G7 C, A# i
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> 2 a/ o1 a: H2 H$ L5 z# @/ f6 @- r<P>Recordset in a multiuser environment. The page containing the record is not </P>% o8 l8 g& G5 f$ |/ E+ w: g$ h
<P>locked until the Update method is executed. </P>4 n" s/ Q$ ^2 m" E
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> ' O) b2 I# }! E* `2 V9 u<P>workspaces only). </P> 9 o& e5 \/ j8 g8 u9 I& U7 v<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> * z6 N/ G' t) w5 r, H U+ ~<P>only). </P> * O4 C6 R0 ^5 ?8 r1 B1 O<P>Remarks </P> * w! @! W: x. Y8 T! b5 a<P> </P>& r" _2 f+ B% B
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> + |0 e3 M8 [# a2 w! f$ N/ G# ?<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>& }# j( t9 d6 s
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> ( y$ R+ B+ T6 g, P2 y<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>1 f/ `/ c# z! s4 o, \7 v
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P># v1 O0 o0 d- @8 K
<P>data source, you must first set the Connect property of the linked table's </P>0 `0 Q0 i7 q: c
<P>database to a valid ODBC connection string. If you only need to make a single </P>9 `# T# [' _) G# |0 V" z
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> 4 `$ P. n9 I3 x4 d) d/ `9 T9 U<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>' h, \& I$ ]3 [ @7 Z/ z$ {
<P>argument. </P> : n j8 Q% R1 a) w' C4 d! b<P> </P># W4 q( S) X% a+ q9 O4 u! H6 h; h
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> p0 E4 s: S; @
<P>is of the same type object. If object </P> ' y: X9 i- H0 t<P> refers to a table-type Recordset object, the type of the new object is a </P># j) E; }8 d( G1 A
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>' K: J6 p0 T0 m- F
<P>杢ype or ODBCDirect Recordset objects. </P> - w" [( ~! _) j2 `! t<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> , T+ X! h4 L* {3 `) \<P>select query in the source argument, such as </P> 8 o1 D% Y0 s/ {) v I+ @( X<P> </P> * b# [- A e! M Y0 e# L<P>"SELECT LastName, FirstName FROM Authors </P>5 S9 x5 E! ~. C; F9 G
<P>WHERE LastName = 'Smith'; </P># w) |' w5 a6 c" O8 v
<P>SELECT Title, ISBN FROM Titles </P> 7 `# {; s8 k; ]6 M<P>WHERE ISBN Like '1-55615-*'" </P> - C/ z- e9 D+ T N2 }<P> </P>/ Z0 y# L& C7 [: @6 X
<P>The returned Recordset will open with the results of the first query. To </P>3 ?8 M/ R/ z A# T1 x. p7 b
<P>obtain the result sets of records from subsequent queries, use the </P> : B( G9 N# U* i s) Q5 l<P>NextRecordset method. </P> 4 t! k3 O; M% E, P5 Y# a3 D<P> </P> . q2 \% }2 q9 B; C2 I6 k<P>Note You can send DAO queries to a variety of different database servers </P>& n8 e/ @$ }2 F8 y$ {
<P>with ODBCDirect, and different servers will recognize slightly different </P> m, ]5 z6 B2 t! \: u/ L<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>0 E% i: V+ q% ^8 Z0 `2 ~
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>3 F) l _0 p5 X Y! j1 r
<P>included through the Help menu. Be sure to check the appropriate reference </P> 8 b) k' @* Y! R& Q<P>documentation for the SQL dialect of your database server when using either </P> + x0 V; O: A. `: M( Q( i2 U; y<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>0 m: A* J% Y$ p1 L- S
<P>client/server applications. </P> / {+ `) I* i4 ?* W$ X% n<P> </P> ' G% [7 T G! x' L/ ^2 m<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>% ]9 \4 F! n8 P+ q3 ~7 N/ P: c
<P>trap changes while two or more users are editing or deleting the same record. </P>4 U) b# K% C) z5 }$ y
<P>For example, if two users start editing the same record, the first user to </P>' a6 F, l- b3 x& r' A0 s5 O
<P>execute the Update method succeeds. When the second user invokes the Update </P> 8 K9 J& x h5 ?( `0 k/ u, Y8 c6 @5 N<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> # f2 m+ R0 I) L2 P1 \$ V2 y) X<P>the Delete method to delete the record, and the first user has already </P> H; B; y {$ D5 k9 S& O
<P>changed it, a run-time error occurs. </P> ; S0 x k6 g6 u0 s" ?5 B4 Z<P> </P>8 Y0 q/ Y8 x. a* O
<P>Typically, if the user gets this error while updating a record, your code </P> 3 p7 ]' P$ f/ c r) I+ y<P>should refresh the contents of the fields and retrieve the newly modified </P> : z- ?' G: w1 m- T& y<P>values. If the error occurs while deleting a record, your code could display </P> 0 B2 j. p( Q) a) R6 y# S) C; N' G<P>the new record data to the user and a message indicating that the data has </P> 0 G. n% T+ s& q! ~# k<P>recently changed. At this point, your code can request a confirmation that </P> " t5 Q3 L ~. `/ j! |6 j2 f- i<P>the user still wants to delete the record. </P> , @% U8 `" E* h8 @/ V* e<P> </P>$ E; y. L8 V# v3 z1 q
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>1 Q0 U+ G6 y$ ~% |! c* n
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>8 V: J% B0 I: N2 O! `, D
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> & \2 G. H% Z; f<P> </P>% E Z8 e4 A# P8 `5 n7 `$ z
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> m. F4 g; q6 W5 H: m Y, x- F
<P>the dbRunAsync constant in the options argument. This allows your application </P> / l4 f/ x! g' B+ p4 N G<P>to continue processing other statements while the query runs in the </P> * V- J5 ^ w. D<P>background. But, you cannot access the Recordset data until the query has </P>3 q* H* j3 Y, I( y
<P>completed. To determine whether the query has finished executing, check the </P>) l$ m0 Y% J8 m9 [7 p% I% m; P! i
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>$ N% N, t" x4 h$ S9 K
<P>complete than you anticipated, you can terminate execution of the query with </P>( r9 m( v+ t) a0 C" M% \. O, C
<P>the Cancel method. </P> 1 w( ^4 S$ n4 P# G! k/ v/ B7 \9 n<P> </P> / H+ W& c9 D k<P>Opening more than one Recordset on an ODBC data source may fail because the </P>4 m" S3 G. F0 D$ g
<P>connection is busy with a prior </P>5 @1 e( V* E* w4 e, [2 t
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>+ u( k: p2 k) Z( s+ L, g4 |
<P>ODBCDirect, if the server supports this. Another solution is to fully </P> / }5 K5 p1 N/ C, F* c' I<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>( l6 ]: J3 @' n( s. X! ^
<P>is opened. </P> 7 K, o/ B; c$ Z- T# O4 x' ?<P> </P> 8 l6 S2 f% t. I% _2 |3 ~9 n7 _<P>If you open a Connection object with DefaultCursorDriver set to </P>. i( c) n9 T! c) q" f1 r3 W
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>/ z! u, Y% D3 f# t
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P># X- K! W2 f3 h# G2 }5 v
<P>h in the lockedits argument to enable update caching. See the Update method </P>- L2 F6 |9 p7 d% H5 w1 Q
<P>topic for details about how to write changes to disk immediately, or to cache </P> " p9 }( m' k; D6 h0 l<P>changes and write them to disk as a batch. </P>8 o9 P" _! p; [: V1 N+ h. k
<P> </P>* i9 e1 ]( E+ b7 U5 P% @2 E
<P>Closing a Recordset with the Close method automatically deletes it from the </P> , n |. i0 T' R+ g3 D" f: p, g6 r0 p' g, D9 L8 Z
<P>Recordsets collection. </P>, X! b& ]* [2 l9 V9 v9 A
<P> </P>$ {/ U- m$ V$ r/ M0 F7 ]
<P>Note If source refers to an SQL statement composed of a string concatenated </P>) r# K) T/ \- G- t, @3 n5 z" P h
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>1 m% R, e" Y$ h0 J @9 Y& S
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P>" u) p# R1 E1 O* K# o& n1 R. v
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P> ) H( Y J3 J9 a" y+ c2 h* M$ a$ \<P>Recordset. This is because during concatenation, the number will be converted </P> 3 |& E7 u; g% [5 _& Q5 z# C<P>to a string using your system's default decimal character, and SQL only </P>* g5 t( v8 g2 s8 M
<P>accepts U.S. decimal characters.</P>