<> </P>3 D* R+ b" O% b1 I- I2 x
<>Creates a new Recordset object and appends it to the Recordsets collection. </P> 8 D$ C w# w0 A<> </P>$ E8 w' l; _3 ^- w/ T- q
<>Syntax </P> ' p- z/ c* W8 m<> </P>6 j+ L& x! B3 T
<>For Connection and Database objects: </P> & w, T# d3 {4 \4 J<> </P>" L- M+ O, p8 W
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> 7 o$ p7 A0 g4 n<> </P> 0 W' z3 B0 p+ E2 _3 ]; u8 w<>For QueryDef, Recordset, and TableDef objects: </P> $ p2 v$ |5 Z# ~4 |<> </P>8 N/ @' w) x: ?) @( g7 w( x- x
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> - Z/ c& n2 f( G7 v<> </P>9 a. `5 u3 T4 y" w5 A" F. @
<>The OpenRecordset method syntax has these parts. </P> , K# y' Y' K7 U& V" p/ s<> </P> + l# S+ m h% O- E( Q3 W- S<>art Description </P> f% q* F _% X/ A
<>recordset An object variable that represents the Recordset object you wantt to </P> 7 H% c5 Z7 g o) [<>open. </P>1 G, N. j) k! y: |
<>object An object variable that represents an existing object from which you </P> * U' B- C- K; `7 S9 n<>want to create the new Recordset. </P> l# l' i0 R8 Q& t/ @( T) @<>source A String specifying the source of the records for the new Recordset. </P> 3 U+ q8 o: P; P<>The source can be a table name, a query name, or an SQL statement that </P> / Z( C! @/ u6 V<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>$ P; j( H4 M& H) Y4 ]; X
<>the source can only be a table name. </P>4 y0 L4 [! Z0 u. V" a: g" \( P8 o
<>type Optional. A constant that indicates the type of Recordset to open, as </P>4 S" w6 d1 R) N' @4 C1 }- m
<>specified in Settings. </P>4 C/ \% a$ c3 ^4 L$ \
<>options Optional. A combination of constants that specify characteristics of </P>- E. d5 w, H. J m" f
<>the new Recordset, as listed in Settings. </P>5 Z H# ~# _: D$ L" Q; }
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> , u. b# A8 W0 s# M* s; F* y' }<P>as specified in Settings. </P> 8 C) {- l( a; n+ y( h" ]: j$ E<P>Settings </P>( T4 _+ p" ?5 b# ^; } v
<P> </P>5 s4 X% ]( N( X$ n/ p
<P>You can use one of the following constants for the type argument. </P>" \/ q2 O% f; b" E2 `
<P> </P> / d. l" `/ e1 Y$ w2 G<P>Constant Description </P> 0 N, O0 O5 U5 m* Z. @. _<P> </P>! K$ P9 } b; ~3 u5 t! x
<P> </P> - Q5 B5 y) q9 h8 C<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P>. {6 U; s \5 ] \
<P>only). </P>- ?" Q1 v4 Y& p Y' e- ~
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>* n! H% a5 x( q6 V; d( M
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>- D: B) {1 U! _) M$ ]$ L! Q% r$ V2 O
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P>, A5 j: p5 l4 S' ^
<P>ODBC keyset cursor. </P> 9 ^4 O5 K9 O% b5 ?7 p- ]<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P> A6 z5 q0 H$ g& S1 T& R! S) ^7 {. s<P>ODBC static cursor. </P>9 v1 }! ~* E, G8 P
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>: M* }! }' u1 t
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>, N) O: x& y; \$ r0 k% ] k% b2 I
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P># N% S# n0 }( p* ?% A, U/ W9 m; b. Z
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>: A% A F( P6 M' ~+ ^7 X
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>8 {, N' N2 _& q
<P>y. </P># q' D, m& q- e
<P> </P> ) L2 t' `6 x* Y9 j<P>You can use a combination of the following constants for the options </P> 1 {3 E! U6 ~7 R; o/ t<P>argument. </P> % }8 h/ G4 ~7 q. z<P> </P>, k5 w' }4 H6 [0 x- s, w3 G+ }
<P>Constant Description </P> 7 i2 @# n8 V' X3 a- H<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>& Q) H+ h$ P3 V! D7 Q2 o
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>) s4 n n9 X2 j$ R3 h+ r" s
<P>dynaset-type Recordset only). </P>& S: g! A3 h5 V1 h6 b- Q
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>; ?5 n: E' ]: R" Z
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>4 k$ s1 `4 `. r: C% W0 I
<P>dbSeeChanges Generates a run-time error if one user is changing data that </P>" l4 B/ W. R4 j6 l$ v
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>" T* h+ ]) @3 A+ x
<P>useful in applications where multiple users have simultaneous read/write </P>% w% |% }$ U; @* G: w
<P>access to the same data. </P>1 n/ u, n1 x1 G* `% @
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>! _% z* f' a7 s: ?; l" Y+ B" V
<P>Jet Recordset objects only). </P> " B" C& C) `3 I" d8 G6 E0 p<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>: x# c; g+ F, e9 c% u7 d
<P>table-type Recordset only). </P> 6 n7 F) @% X- j4 Z<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> $ P- |& E6 b/ j<P>Recordset only). It is provided only for backward compatibility, and you </P>, l( u* A( b* p% v, N% ?
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P> . i, |7 Q2 h. S. s<P>using this option. </P> * k& `( W: p$ \1 h: P<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> : K4 i6 V. G9 ^0 Z<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>3 E5 m: w* J5 z6 B3 ^: Y/ Q0 v
<P>option, which is provided only for backward compatibility. </P> ) Z5 K: j4 Z/ p<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>0 W* y: o0 s8 f* d) q
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> 0 _) e( D6 q2 X<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>. S2 u2 e3 Q* A* W
<P>not opening a Recordset based on a parameter query. For more information, see </P> 2 Q8 U8 n8 z4 ?5 i1 \<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P> ! y6 T9 I5 D( Q, J* D* ?<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> , {) z N" y$ i3 ~4 u( }% N<P>snapshot-type Recordset objects only). </P> 5 _0 u9 v1 g0 ?$ W" v# u<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> ! ~ i2 G( @6 l: J0 `1 a5 P<P>snapshot-type Recordset objects only). </P> 5 L% P; O0 d7 k<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> ; \5 i% K: l0 E. U4 Q0 M- C<P>and using both causes an error. Supplying a lockedits argument when options </P>2 ^$ Y# x& h* J$ V0 Y" d# [) w
<P>uses the dbReadOnly constant also causes an error. </P>7 J1 w# F+ d8 I
<P> </P> # |2 _' W1 D, ]<P>You can use the following constants for the lockedits argument. </P>% z# \' ^' j2 |6 `) x$ c
<P> </P> , u, D5 b7 ~& t* H8 J<P>Constant Description </P> v) _. T w3 V7 x: R. h<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> $ I/ `6 ]; e" a0 p, R<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> 8 k, @1 g4 v* C0 u2 W<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>6 X! i5 ^/ X9 o1 Z# M# L
<P>run-time error occurs. </P>+ y* E9 X9 @ B. g
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> : z! ~; V& L3 B<P>the Recordset in a multiuser environment. The page containing the record </P> * {5 P3 y5 {# p9 D" E<P>you're editing is locked as soon as you use the Edit method (default for </P>8 | ^7 a2 F7 F& z. o/ z
<P>Microsoft Jet workspaces). </P>1 c( n9 o1 S2 l) x
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P># ^9 W. q% }% {) S# c! f& _
<P>Recordset in a multiuser environment. The page containing the record is not </P> , {- n0 p# m( f8 g( \7 ^' v! k<P>locked until the Update method is executed. </P> ' U! c3 s' v( c; j8 S& o! D<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> / c4 {7 f& q7 U<P>workspaces only). </P> + j7 t9 q* Z2 Y4 P1 ]/ c) x x8 J<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> + I O8 I# W6 N<P>only). </P> & K; y/ @, b( o1 Q3 X, C3 Y<P>Remarks </P> 9 A) _% a t$ U! T3 G<P> </P> 8 I" u5 y/ w9 ]# Y+ l<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> 7 O3 v) C" W9 D# W<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>/ Y2 |' F8 c6 @' f2 f
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>% Z& z7 w# H" r g
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P> . |! r7 A' [7 r( l( u5 J<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>$ n. p, \1 i5 Y6 a, e* }- h
<P>data source, you must first set the Connect property of the linked table's </P>6 c* Y% s) G+ Q" }5 G
<P>database to a valid ODBC connection string. If you only need to make a single </P> 1 ` Q! W( n* M4 p8 S. R# J! z! ?<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> 3 ?3 Q+ p( P. ]7 g. Q<P>source, you can improve performance by using dbOpenForwardOnly for the type </P> 7 ?; b/ n6 E+ y# ?) U" v<P>argument. </P>9 Y/ B0 W5 j. K7 K
<P> </P>' A0 P0 ^" @7 y
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> / W& D: A! M$ ?6 s# G- K, I/ N<P>is of the same type object. If object </P>( Z. j. U5 X) G- x7 E9 ^
<P> refers to a table-type Recordset object, the type of the new object is a </P>5 U' D: Y6 q) e& D
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> 4 g" y" c1 P& S<P>杢ype or ODBCDirect Recordset objects. </P> " S: @6 G5 b, `% {/ N<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> , w2 Q( Y/ b u& Y4 q6 ^+ ~" d% W<P>select query in the source argument, such as </P>. J+ T9 ^5 e1 z! C
<P> </P> ! G/ C# k/ f3 E2 q# J" c<P>"SELECT LastName, FirstName FROM Authors </P> & r$ M( b3 G U5 B<P>WHERE LastName = 'Smith'; </P> \5 q+ {" C8 P; }" t4 z- S9 v X
<P>SELECT Title, ISBN FROM Titles </P> ! ]4 U3 V' H8 r4 o4 u) R. W<P>WHERE ISBN Like '1-55615-*'" </P>9 v9 Z$ S% d+ j) ]: ~ n: |! p
<P> </P> ( y( @7 Q% K& {2 G4 E<P>The returned Recordset will open with the results of the first query. To </P> 2 h) E6 v6 _' y6 v/ @6 }<P>obtain the result sets of records from subsequent queries, use the </P> - M) G+ u% ?9 E/ D<P>NextRecordset method. </P> & `# T$ n& o# Z' M/ R8 k2 P+ B/ A<P> </P> * n" t1 ~# X+ _: ]/ V: s, R<P>Note You can send DAO queries to a variety of different database servers </P>0 ~( o5 r$ h$ y( j1 a
<P>with ODBCDirect, and different servers will recognize slightly different </P> ) l [1 f% ]8 b/ c. R# ~<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> # ]1 K3 ?7 f' ?! h; [<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>) m9 Q& N' I- X- d8 Y) w
<P>included through the Help menu. Be sure to check the appropriate reference </P> 6 b6 G7 L* M1 A: f+ b<P>documentation for the SQL dialect of your database server when using either </P> , w" a' X( [9 A; E7 b! C<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> ' b6 R% [; L. h( m8 A<P>client/server applications. </P>$ m% U" ?: B: g" A) @8 O
<P> </P> 2 K* E- ?& z: r5 _<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>! ^$ L' U6 t: c' _! `2 _2 [4 i
<P>trap changes while two or more users are editing or deleting the same record. </P>9 L8 z9 g% \9 k9 Z# {& b" _' b
<P>For example, if two users start editing the same record, the first user to </P> 4 L" G, O2 }: W! f<P>execute the Update method succeeds. When the second user invokes the Update </P>) V+ k9 f1 Q% S3 z" H
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>8 j: y. g5 w2 s3 V
<P>the Delete method to delete the record, and the first user has already </P>$ _# W+ X- w3 Y5 T! u
<P>changed it, a run-time error occurs. </P> n* D: c9 w: d' o5 A5 u; f- k
<P> </P> ) Y+ j. k9 _, c _. b0 I; L! L0 e<P>Typically, if the user gets this error while updating a record, your code </P>/ d& A3 G( l7 [' f
<P>should refresh the contents of the fields and retrieve the newly modified </P>% O7 I% e0 ]( m# e4 `6 c/ w, E5 p
<P>values. If the error occurs while deleting a record, your code could display </P> . E- [# Y# _3 ?! W3 i. Q' Q+ [6 Q" x<P>the new record data to the user and a message indicating that the data has </P> 4 F: L% `0 C8 W6 a- T<P>recently changed. At this point, your code can request a confirmation that </P> 7 O1 P; a' X% i6 c<P>the user still wants to delete the record. </P> ; j% n& ^3 D% `$ H<P> </P> 5 h" Y' h! C2 h# X8 l3 o! U<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>1 h' t. B7 h' S e9 S8 X+ C0 j
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P># `0 v( `& b4 f" S; O
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> {4 N9 \/ O9 H. i; m9 H5 d
<P> </P> 6 H4 S- d' a6 A0 v<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>2 a7 O& k" W+ d, K1 Q
<P>the dbRunAsync constant in the options argument. This allows your application </P>5 a+ C! W% v" |+ h
<P>to continue processing other statements while the query runs in the </P>4 q2 o$ K9 T. j+ v( k
<P>background. But, you cannot access the Recordset data until the query has </P> & S' |+ G7 [" s* f# w' l<P>completed. To determine whether the query has finished executing, check the </P>) y( k. Z: b& T8 ], m& u
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>% D2 ?# G- Z* c( p% z( `
<P>complete than you anticipated, you can terminate execution of the query with </P> ! v& V! G s+ n0 ~) g) |- F<P>the Cancel method. </P> / G1 L( _2 e# Y* q( @; S5 R<P> </P>! V/ ` Y8 T2 x7 n" S( d; T4 e
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> ' A/ }' C8 z# e+ w$ y: q! L4 e) D<P>connection is busy with a prior </P> 4 D Q, g% Z8 Y3 m4 s( c N9 W8 H<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> ! M4 r6 d# I+ l0 F8 {+ V<P>ODBCDirect, if the server supports this. Another solution is to fully </P>) v1 h& Y6 i! i2 ?- S
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>5 f+ T1 {, V: x1 i
<P>is opened. </P> - _0 U: t0 L$ l, _- A: B5 O9 j<P> </P> 8 U# g9 w* K6 `& s9 t0 o7 @, X0 l<P>If you open a Connection object with DefaultCursorDriver set to </P>1 v+ W; j3 {" y
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> : T, `! N [- @8 F k8 c6 N<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P> , Z9 j# | C: N9 ]4 O6 K/ Z<P>h in the lockedits argument to enable update caching. See the Update method </P># K" L l3 A- j7 N; M8 X4 p( P- a
<P>topic for details about how to write changes to disk immediately, or to cache </P> p2 R' H6 _& K5 D<P>changes and write them to disk as a batch. </P> ) ^2 v$ K% p, R/ _+ u+ T+ `<P> </P> 9 v; Q9 ^! f" @<P>Closing a Recordset with the Close method automatically deletes it from the </P>& N4 l# z$ n% e5 s L- z" x/ s2 ~- b& `
6 {0 v( e5 c" A+ Z7 ~<P>Recordsets collection. </P>: I; q. _0 D" V' I
<P> </P> ; t& L4 d$ X$ q) D0 @<P>Note If source refers to an SQL statement composed of a string concatenated </P>. d8 a1 a! i5 l
<P>with a non-integer value, and the system parameters specify a non-U.S. </P> * K7 j& I; `- d7 A<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> / i; Z- e7 q4 _1 {# A% K4 \% y<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>, g6 O4 Q, r; n% I7 ^5 w
<P>Recordset. This is because during concatenation, the number will be converted </P>, Y( d- T- d8 J+ k2 m' A' N: ~- E
<P>to a string using your system's default decimal character, and SQL only </P>: D0 P; ~/ l, G+ L
<P>accepts U.S. decimal characters.</P>