<> </P> % E1 U$ q+ v4 h. x! W; }<>Creates a new Recordset object and appends it to the Recordsets collection. </P> 5 q/ N: R7 _: C8 G" r! T<> </P> ( W# D- y6 H) \ g0 X<>Syntax </P>; H2 ?+ K* k V
<> </P> - t$ w& Z3 o8 L<>For Connection and Database objects: </P> , S& @9 D/ W% v! |/ X( o* Y3 B" P<> </P> # b _8 }$ g# m1 Y" a<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> - D# r0 ?3 j( y3 U; ]( d<> </P>' ]% p3 Q/ V5 F, W! M* }) M( J: `
<>For QueryDef, Recordset, and TableDef objects: </P>% y# I: s* i. O
<> </P> 4 X. g& l- s1 [% c* ?: c<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> ( z4 @8 k3 [& _' V<> </P> , `5 m( `% i1 n; t, ^( K<>The OpenRecordset method syntax has these parts. </P>* d2 P" Q3 F- H4 _- z
<> </P>$ b1 T/ I2 Y" M' U
<>art Description </P> : l5 P& [; A* l<>recordset An object variable that represents the Recordset object you wantt to </P># @0 C; T. V9 P5 Q/ h# U: B
<>open. </P> - Q( x4 C0 q ]3 L3 C, y<>object An object variable that represents an existing object from which you </P> 7 S7 R7 V/ Y' Q! V3 H. J$ o T<>want to create the new Recordset. </P>& u, F; v2 T& R( A
<>source A String specifying the source of the records for the new Recordset. </P> 2 ~6 v% v1 O3 m, s4 q<>The source can be a table name, a query name, or an SQL statement that </P>9 [; k& H3 F. ?; t# |- [3 y( H. t
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> : Y0 e5 @$ l4 P0 b' v, S<>the source can only be a table name. </P>9 V9 b0 }; d' F O9 \/ `1 Z2 M
<>type Optional. A constant that indicates the type of Recordset to open, as </P>+ w- y0 U! U6 i0 d* K' z$ R! Z/ f
<>specified in Settings. </P> * @3 A& D6 \( i2 [& Y& j<>options Optional. A combination of constants that specify characteristics of </P> 8 H' H9 X7 Q' K' |<>the new Recordset, as listed in Settings. </P> U: i8 H* X( Z
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P>: X7 z& t! }$ Q2 @ t. Q d7 {
<P>as specified in Settings. </P> 8 I3 T/ I0 `+ E" W( I$ R<P>Settings </P> & S; Q. Y. @$ F6 I; r2 h, R |' D9 P<P> </P> 7 z3 G% P' g$ a8 Y<P>You can use one of the following constants for the type argument. </P>" `: A: _6 f) V" |! i2 ^9 C) Q
<P> </P> & G5 ~3 a9 S, b2 J" j: B5 w8 O<P>Constant Description </P> 0 Q2 u: n8 x6 x# ]# h: t/ a<P> </P>4 h, I1 P/ ]4 W3 S! T+ i6 Z$ l
<P> </P>& f8 B" @& m7 r# B! L5 u! H" Y! Y5 r
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> , n) t, _( N$ d# T<P>only). </P>4 J" t$ ~& g/ {
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>9 K7 i3 n+ F- d" P. ^! ]% Z- G k
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>$ E* i* r$ D( z- e- ^* K' Z5 z
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P>/ u- r; w% b6 g2 x% E5 g
<P>ODBC keyset cursor. </P>6 {9 T6 z3 c; f1 T$ L" ]$ ^
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P> , y; }5 @9 ?# g3 @<P>ODBC static cursor. </P> # t0 `4 Z2 e+ t' K: R3 J, p<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>. d s( V1 e6 H1 A! @5 l
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> 0 s. L( f% y% p+ F T& X8 K<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>% U0 q8 N1 R% H: \7 T
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>9 G9 H* Y$ a: x, n! F: Z
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P> # I, ~7 S6 o! G6 h! b7 \: u0 c<P>y. </P> 8 b; q6 [& j7 E+ D5 P9 j, h( |<P> </P> - n! X: Y2 T$ H# W a3 L( E1 C<P>You can use a combination of the following constants for the options </P> & M7 I+ t* T% O0 N& J" p; Z0 Z<P>argument. </P>$ e+ u/ |( c- m) o# Z
<P> </P> 1 o- t6 n8 m8 p8 |, p<P>Constant Description </P>4 }; M3 Z$ l( Q
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> & r; y o$ h0 v3 U<P>prevents them from editing or deleting existing records (Microsoft Jet </P>1 |6 k3 `# n# P
<P>dynaset-type Recordset only). </P> 1 Y3 L) c4 m3 L( w. U4 W. z2 }<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>3 ?9 ~0 a! \7 g8 ^5 |
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> " O1 H r& `: D% D; [& h<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> # Z( C& Z! p0 r<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>% T$ g; @) }" r0 S- q2 E- B, {
<P>useful in applications where multiple users have simultaneous read/write </P>. d) [- Z N, U$ w& s% E6 }) V% X
<P>access to the same data. </P> 6 l/ y/ h8 m4 j7 h: Y<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> ( z( h; @& a M<P>Jet Recordset objects only). </P># d3 S. @% L0 z. d" G
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> 2 c7 } O& Q( N K$ {1 G; H' }<P>table-type Recordset only). </P> 1 u) w7 l- N* e/ Q }' q @. j<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>" J! s8 G1 U1 s" f; g2 t- H
<P>Recordset only). It is provided only for backward compatibility, and you </P>, V9 e" u1 U) d O3 X3 A+ U M# V3 s8 f
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P> P7 y% z& H& G1 V0 `8 {5 W- S<P>using this option. </P> % B: Q" @; {& |<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> - s9 e2 d" U' D4 M<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>1 _5 B! R0 x5 a( v: x
<P>option, which is provided only for backward compatibility. </P> ) k6 a, s3 U# e" n& P6 D: @<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>& A. z( i: q) U+ Z3 E
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> . r. [% Z5 `, R& q, r- |<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>& _) ]" G2 S, y* j
<P>not opening a Recordset based on a parameter query. For more information, see </P> 8 A2 ]0 C, c$ `; `<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>% t. N6 i+ |1 F* v; y q
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> 2 }5 o" F* f. m" G4 O<P>snapshot-type Recordset objects only). </P>! ]& d6 H, r# c' s8 F5 e
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> , }9 n# k1 { E& Q* u/ K+ d<P>snapshot-type Recordset objects only). </P> - Z* j' I. d- {8 K7 B6 Y0 |<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> : X2 `9 t8 Y4 m2 W, V- t9 v<P>and using both causes an error. Supplying a lockedits argument when options </P> 3 s, I) z7 d' Y" V& [4 i<P>uses the dbReadOnly constant also causes an error. </P> ) l2 p7 |9 D$ |5 @" j6 u0 W' e<P> </P> + H/ J; T. ?; {9 E/ u<P>You can use the following constants for the lockedits argument. </P> - g" _0 S5 \' L& A<P> </P>, s$ `: B. ]4 _/ R3 ` N
<P>Constant Description </P>( _! s. b3 b: R u5 O
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>1 e6 F( l% T- i# s9 p
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>5 ?. @( @# b8 \4 i3 l# Y) }
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> $ t7 m& d# I# V<P>run-time error occurs. </P> 8 }. S5 i2 k% o" }# b( g7 R. Z6 X3 ?0 Y<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>& l) Q/ }% o( J' M# }/ Q: v
<P>the Recordset in a multiuser environment. The page containing the record </P> # p8 `; m9 E( x<P>you're editing is locked as soon as you use the Edit method (default for </P>$ A0 ~* H, r" |5 g
<P>Microsoft Jet workspaces). </P>+ @; X& p$ A H" ?& s# g V
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> " |) U, @& ^$ d' [( z L6 F! T: J<P>Recordset in a multiuser environment. The page containing the record is not </P>, y8 w8 I1 [! i$ A
<P>locked until the Update method is executed. </P> ; ~/ q* x' s/ J$ D0 a<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> 6 E% T" ]0 }9 M. _1 N<P>workspaces only). </P>. u. u( A) |$ a$ l1 B8 f
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>; Z8 O |! W k) p/ h0 B6 H* Z
<P>only). </P> 9 E: G! _& c4 Y0 n6 S1 J' E1 b8 ^- c<P>Remarks </P>8 t) h4 ?" o( t1 L) t( h+ s
<P> </P>7 v8 O, l- w6 x+ M/ G
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>8 K( G5 t" O3 }2 {- c
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> & `: c+ O u/ H, v2 O' s: i<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>% H0 w' l7 E7 z$ B! }0 Z
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P> % y2 f% |* ~. L* q6 b<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> ! j& M# k1 h G* P% d: v<P>data source, you must first set the Connect property of the linked table's </P>/ q4 A% G' r: o! v Y( ~, E0 \
<P>database to a valid ODBC connection string. If you only need to make a single </P> " P3 C5 k( Z! ?! {- Y z u9 N+ l<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> % Q o5 }5 d# n3 [# ?) w" Z<P>source, you can improve performance by using dbOpenForwardOnly for the type </P> , J* @7 r- w+ W% M/ U, L<P>argument. </P> , Z5 h! K# y0 l& F' k# w<P> </P> 9 d- `+ O9 s$ X e4 d! C<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> ! r$ G3 }7 K& p, M {- _<P>is of the same type object. If object </P>% h7 q1 E$ Q Y# P$ f& l# Z/ E
<P> refers to a table-type Recordset object, the type of the new object is a </P>: o9 Z6 @& A& p, n+ |9 Z' b1 o5 \! U
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>4 e7 Y! r' ?* A: K4 V
<P>杢ype or ODBCDirect Recordset objects. </P> / G' P8 _: N- e" H<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> 9 _- \, O& p' X! D5 p' v<P>select query in the source argument, such as </P>0 d! e* _) r( V: B, r2 f \
<P> </P># W) y4 X! ? W' A4 b, @9 b
<P>"SELECT LastName, FirstName FROM Authors </P> 0 f! o* O; x4 s3 s' j<P>WHERE LastName = 'Smith'; </P>" \5 q! s# x2 \
<P>SELECT Title, ISBN FROM Titles </P>+ {6 e2 h X. n2 U
<P>WHERE ISBN Like '1-55615-*'" </P>$ E* w) ?' u+ C, |1 P! M3 F
<P> </P> & G3 h/ H+ Y# X$ G<P>The returned Recordset will open with the results of the first query. To </P> ) b" w. G# A! N: e7 | v<P>obtain the result sets of records from subsequent queries, use the </P>3 p0 g$ Q) t) o# v( Y0 \
<P>NextRecordset method. </P> 3 C0 q) V% A/ X+ T<P> </P> , [5 y- h& H+ w% r( u<P>Note You can send DAO queries to a variety of different database servers </P>2 Y7 x: D- U" p9 `& U) f
<P>with ODBCDirect, and different servers will recognize slightly different </P>% i( P0 L1 |$ {" d
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>% q" ]7 j/ [& s" P, `
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>9 r* N. w& P' _0 @3 q# j! Y
<P>included through the Help menu. Be sure to check the appropriate reference </P> h5 v! j4 b8 L/ k
<P>documentation for the SQL dialect of your database server when using either </P>+ A3 {5 p' `( d* p% I
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>8 k% m/ y3 Q% w3 N F0 B& ~
<P>client/server applications. </P>( p. j. @* c" H
<P> </P>' g& T8 W) u! }' N1 H
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>1 Q" U* l$ {% A, D* w; t+ w5 G# j
<P>trap changes while two or more users are editing or deleting the same record. </P>/ k8 ]3 L- Q; ^' Z4 R
<P>For example, if two users start editing the same record, the first user to </P> r; h( w; [" Y7 D5 X
<P>execute the Update method succeeds. When the second user invokes the Update </P> % v" p0 `" e. w<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> 0 P8 S( Y! b/ t* X6 ?; |, D* [/ l<P>the Delete method to delete the record, and the first user has already </P> 2 i1 A. d& X: d' {7 \4 B<P>changed it, a run-time error occurs. </P> 7 }3 P) F6 q3 q9 g/ d9 O6 ]/ Q `<P> </P> - `- t0 N3 B0 ?2 M/ Q, B<P>Typically, if the user gets this error while updating a record, your code </P> + M y& R$ |0 W* K" }% r# |: m<P>should refresh the contents of the fields and retrieve the newly modified </P>/ |6 ~6 W. ?- `! v0 N
<P>values. If the error occurs while deleting a record, your code could display </P> 5 Y! B. M2 Y1 @<P>the new record data to the user and a message indicating that the data has </P>; f5 i0 `% j: \/ N5 a
<P>recently changed. At this point, your code can request a confirmation that </P> ! \# k1 b. o! l9 c7 \4 ]<P>the user still wants to delete the record. </P> - [8 t3 {- P% X: R8 D2 C' f<P> </P> # G2 \8 \ z! g5 j9 b( u, e/ ^<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> u* }/ ]( m1 b- K8 v- ?
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>$ N) H4 \" V- Z4 g$ J% d
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> * N' [& h5 I$ p4 t! R; @/ z- J<P> </P> ) F, I- p( Q9 s: i0 H+ p<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> 0 M% g8 z. i1 E: t6 m7 R<P>the dbRunAsync constant in the options argument. This allows your application </P>1 _/ B* k/ @9 g
<P>to continue processing other statements while the query runs in the </P>/ i1 @" @" p5 w
<P>background. But, you cannot access the Recordset data until the query has </P>0 ?* I. o, m4 O7 ^$ L \
<P>completed. To determine whether the query has finished executing, check the </P> 7 Q0 M1 Z: e; |" ^$ E% W! a3 }<P>StillExecuting property of the new Recordset. If the query takes longer to </P>- N8 P+ d3 ^/ W: Y! h- N
<P>complete than you anticipated, you can terminate execution of the query with </P> - K- P5 w$ p ] w) y<P>the Cancel method. </P> 3 Q# v9 u; d" ~# n<P> </P>, L3 @: x, [7 R8 w d6 M( t8 ?
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> ; k& o g4 v, o/ N6 g* v4 }6 @7 @<P>connection is busy with a prior </P>, `5 C# s- w1 U3 `$ `
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> - @" o0 I3 d% I; S& u<P>ODBCDirect, if the server supports this. Another solution is to fully </P> 8 G3 @# e$ W7 P0 `1 s# j<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> , I4 n/ |* I3 b. W; d<P>is opened. </P>9 o# L) c5 x1 W, ^
<P> </P>$ c: N/ N( _, w" ^' l. z
<P>If you open a Connection object with DefaultCursorDriver set to </P>+ h; P9 w2 G6 N$ ^7 w' L6 R* s
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> * t6 r+ t8 J4 f' e8 e1 E, \<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>" D& N. ? x0 G9 ~( e3 H5 E* g- n
<P>h in the lockedits argument to enable update caching. See the Update method </P> " S5 D: D( H* j8 P2 [+ m# j8 i<P>topic for details about how to write changes to disk immediately, or to cache </P>- u8 b6 W* n% m8 t
<P>changes and write them to disk as a batch. </P> ; b" v. N# X" }6 i<P> </P> $ J; V5 `$ u2 N* l<P>Closing a Recordset with the Close method automatically deletes it from the </P> 2 Q; D# o2 [5 o6 y1 f0 Q. ]2 R# A+ Z1 z9 |6 g
<P>Recordsets collection. </P> 1 v F$ L0 m+ e0 @" o$ u; j<P> </P>- p/ r9 u }* y- x) T- r( i. W
<P>Note If source refers to an SQL statement composed of a string concatenated </P>% z; E1 E& R z6 ]& u& D' q
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>( E1 R7 @' y; p) f- @9 ?! P
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> ( S) P/ X1 E* _+ n& B& v<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P># {: p9 p2 ^- n! X: p* Z: w4 P
<P>Recordset. This is because during concatenation, the number will be converted </P> 7 V. _! {, M' w& B" Z5 B3 s<P>to a string using your system's default decimal character, and SQL only </P>+ c0 s& m/ i* |5 S: D7 \
<P>accepts U.S. decimal characters.</P>