<> </P> & p2 a5 g' x% {* r, E<>Creates a new Recordset object and appends it to the Recordsets collection. </P> ; D, x' k( t' i( O<> </P>- O# u- k+ ?* ]9 O4 N, v7 G! f
<>Syntax </P>) B: Y7 h4 o5 O& l5 u1 W
<> </P> / w$ M+ b1 k' G' N( E+ p, q: T7 j<>For Connection and Database objects: </P> & Q r* L) v2 B9 f9 Q+ ?<> </P> : S. `6 J* {/ k* o<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> 9 f3 Q7 ^+ H H' l% M" `<> </P> * U" \9 I) o3 Z<>For QueryDef, Recordset, and TableDef objects: </P>. a' q, L7 J4 ^6 l/ E
<> </P>, X% L' R- ~8 ]. @8 O' V2 T
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>7 k9 l+ O$ v+ u9 @# ~- A# B H( [
<> </P> 6 c' F: h* I0 e9 ^5 J7 [2 ~% x# Q. H! e<>The OpenRecordset method syntax has these parts. </P> 7 e, O+ K- ?( j- e9 X, a<> </P>+ E( W) H& i+ t$ o- I
<>art Description </P> 6 U. |/ d( a) K/ D7 T( n: E1 \<>recordset An object variable that represents the Recordset object you wantt to </P>" d' D$ k+ d) g
<>open. </P> 8 y2 |; j0 r5 N9 d$ o0 Q8 o<>object An object variable that represents an existing object from which you </P>3 A6 z1 I' D9 {3 j. s0 R: i" K
<>want to create the new Recordset. </P>9 ^0 [9 l; B+ w
<>source A String specifying the source of the records for the new Recordset. </P> , o: s. l. i+ [; S9 g' A<>The source can be a table name, a query name, or an SQL statement that </P>9 n( D8 o' |! y9 E; T* [- F& Q+ y
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> $ t" q8 i4 H- {3 e- G, _' w<>the source can only be a table name. </P> , |" h9 |. H4 T8 L/ l8 I8 B6 U<>type Optional. A constant that indicates the type of Recordset to open, as </P> ) i% M9 j5 I& K* Q# U<>specified in Settings. </P>5 B- O. b' s$ i4 b' u" J' y$ V
<>options Optional. A combination of constants that specify characteristics of </P> . F" h# m5 Z. _' m<>the new Recordset, as listed in Settings. </P> ; ^8 M6 t% d/ g<>lockedits Optional. A constant that determines the locking for the Recordsset, </P>$ H$ G, s0 l2 Y% |
<P>as specified in Settings. </P> ' J8 o: O5 K* `, n/ K<P>Settings </P> ' t/ j" G8 i% @/ N/ b<P> </P>' X" p, p7 p8 _: ?( ~' h' s
<P>You can use one of the following constants for the type argument. </P> - o; V8 e }/ ~# s% x. p& e9 i. M& \<P> </P>- A% E a4 y3 n+ W
<P>Constant Description </P> 7 X/ Z, s$ T V3 l3 w<P> </P> ( V E% d ~. H7 m3 M3 y- P<P> </P> 2 R8 q4 O" @4 c; L% d<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> + O* z' G# K& l9 H) Y& z<P>only). </P>& G/ ^* i; z; }, k" R& Y% n/ D
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P> 2 ] R8 W8 S9 B6 h/ R6 G$ k5 J, l2 Z<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> 9 a* |5 b3 V. d9 X! l3 J# D" B5 ~<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P># s% p9 \ K7 p
<P>ODBC keyset cursor. </P>( w: ? ?$ h7 V0 Q" ~; F2 j) q" x
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P> + B+ r, J/ F: I9 H<P>ODBC static cursor. </P>+ h! a: ~5 d+ @1 w+ ?8 |
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>8 @1 Y/ D/ J" ?. h" z( H
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>; H9 r9 U3 k' R1 R/ M6 H
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> & \" [: v9 t* t- ?0 m( p1 u' d- p<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>' e9 J; P6 M0 e) ]/ S
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>, {& M9 a5 S- `1 W
<P>y. </P>3 j. L9 t5 g4 F9 i, H! ]/ {& b
<P> </P>; y* } I/ P* ]) O
<P>You can use a combination of the following constants for the options </P>* a G/ ]8 e& {5 O5 l6 D
<P>argument. </P>: c3 N) [# m/ r
<P> </P> ) b$ S9 T, b; |% |* I<P>Constant Description </P> 1 H3 ]2 c: a1 i( e: X" ?<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>$ A5 _5 g2 e$ a; ~0 s
<P>prevents them from editing or deleting existing records (Microsoft Jet </P>. I+ L( ?9 ]( p d# v1 }
<P>dynaset-type Recordset only). </P> 6 B+ B; _% _& Z$ K* s<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> 7 q( m6 [# N) ~4 s1 p1 X<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> + j* x! Z& F" `1 w6 t& v! _<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> & U2 W, T1 ?- R, i+ ~+ y<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>+ E1 W6 n6 T1 b
<P>useful in applications where multiple users have simultaneous read/write </P> : G3 K& n5 U! d' k* ~<P>access to the same data. </P> , L+ f" ]$ S! `2 A t<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> ]# g0 Z x' n4 r4 S0 G$ y
<P>Jet Recordset objects only). </P>3 l9 `2 s* J, D& m
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> i/ N# x6 C+ Y z2 B0 Z
<P>table-type Recordset only). </P> # s3 G$ i0 ?& Q |1 d<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> 0 m& w/ w; I( F% G! q1 _<P>Recordset only). It is provided only for backward compatibility, and you </P> 1 `' V( J4 V" t" @- Q, T4 f<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>. E7 V% V/ q/ q/ T6 L& [) I: ]
<P>using this option. </P>, Z( c; Y; g" w( P; V
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P># c. N. t' _% z6 ^
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>+ C, P9 i: V v4 j1 J
<P>option, which is provided only for backward compatibility. </P>7 y$ t( F) R- s' L) J
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>; ]' ^: j7 \3 z* v, ?3 p; X
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>$ X; d8 Z4 W) S+ b L2 m1 w
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>1 i7 B c- S% M
<P>not opening a Recordset based on a parameter query. For more information, see </P>* ~9 j0 W, q; S& H; S, c
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P> 1 s5 J1 F% Q1 T. ^& B) u4 Q" P<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>- E$ n# l" R0 K8 y0 a7 u
<P>snapshot-type Recordset objects only). </P>" ?8 z7 U+ ?0 [8 m: p
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>9 E2 W$ M# W; Y5 h! \2 w& k
<P>snapshot-type Recordset objects only). </P> 2 a" z% C+ o- L& @<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> & R: a& {/ U1 U0 _# y; G<P>and using both causes an error. Supplying a lockedits argument when options </P>3 `% j9 N& y" E) E
<P>uses the dbReadOnly constant also causes an error. </P>* E$ y7 b8 Q9 W& J8 |2 ~4 k
<P> </P>+ E6 u3 @0 i3 n
<P>You can use the following constants for the lockedits argument. </P> 5 n2 [# W* Z! g* f" s<P> </P> % a" C. K% \; v<P>Constant Description </P> # ?7 @2 Y( e+ K7 s8 E; K r" e, Y<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> . U. @1 z/ t; w F<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>" G1 l; W; k8 }( n* R: q( j% w: O
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>4 q* }1 u* j7 ~+ N! O; t* G
<P>run-time error occurs. </P> . I8 A- \% U5 y1 Y+ q; e<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> 5 p, Z, w$ ^% H/ R$ h<P>the Recordset in a multiuser environment. The page containing the record </P> $ t; S' Y- p4 e" I6 x<P>you're editing is locked as soon as you use the Edit method (default for </P>; ?) Z4 N2 q4 Q( E* r* W4 \. C
<P>Microsoft Jet workspaces). </P> - v- a. E7 T: T$ \! p3 R<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>) k: d: H# Y) D; ~5 p
<P>Recordset in a multiuser environment. The page containing the record is not </P>1 |' r2 a& V8 j9 n. ?% Q6 O. ]& J6 q
<P>locked until the Update method is executed. </P> 7 `( ^% i6 K( ~# q' ~& w' \7 L: I<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> 2 |7 ^/ M0 G* a% a" P<P>workspaces only). </P> 7 |/ O0 m$ S+ X& f6 j<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> * ]0 ~# c) I/ \6 |7 u<P>only). </P>7 \1 N5 ?2 G& `: ^; _( Z# k2 F
<P>Remarks </P> 4 T' B' k, G- \4 t, c3 d# q2 @<P> </P> 9 \3 [9 E6 b) B: W& ^<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> + A- k3 j( r# B N" ^<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>8 I8 e- v- j) U! E# N/ c f
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> 3 ]6 Y7 @) J/ c, Z<P>the type argument; if you do, a run-time error occurs. If you want to use an </P># Q% h, ^, W! Z0 K1 }! T
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>. u; @/ a n! l# G$ \
<P>data source, you must first set the Connect property of the linked table's </P> 8 W: v( e: {; C# C3 X. R<P>database to a valid ODBC connection string. If you only need to make a single </P>9 q0 k P; {; e' W
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>2 l5 b2 x3 L+ b2 Q5 Z* V C9 I
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>4 ]7 r" r4 R' v( D9 G( B" L7 i0 p; x
<P>argument. </P> * y2 k) z2 z# {- ~. e- [' e: i1 p; U<P> </P> # T( \1 M3 R( f5 g4 U F0 U/ o' u<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>- z. g5 L" l4 c$ E# s$ h
<P>is of the same type object. If object </P> : I7 m* Q( R4 ~. A% _$ E( \$ n<P> refers to a table-type Recordset object, the type of the new object is a </P># g6 G5 R3 x$ k _, C7 z
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> 9 |6 S, r' M& k, Y8 ]<P>杢ype or ODBCDirect Recordset objects. </P> 6 A+ o* u x* b n% \; Z<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> * J' c4 H& E) y9 a* w4 D<P>select query in the source argument, such as </P> * _! ?/ f3 T2 ^2 p9 e' P<P> </P>, U0 p4 Y/ a! N$ T& o' K
<P>"SELECT LastName, FirstName FROM Authors </P> 9 R' Z3 K& E! D, Y7 d- I+ Y# P) Q<P>WHERE LastName = 'Smith'; </P>' j' _& \1 c% }* E
<P>SELECT Title, ISBN FROM Titles </P> 8 }1 t4 A' p$ B<P>WHERE ISBN Like '1-55615-*'" </P># L' [& g [% }* k$ X
<P> </P>- n# E) Z Q7 i* n
<P>The returned Recordset will open with the results of the first query. To </P>0 o5 \7 x0 I0 p* ]& C
<P>obtain the result sets of records from subsequent queries, use the </P> # F' J9 n: g( C6 v9 A<P>NextRecordset method. </P>" ]+ y5 p+ @! f4 v5 [6 D# ~# R" g
<P> </P>+ z" W& o4 m/ c" h$ j6 E4 ?
<P>Note You can send DAO queries to a variety of different database servers </P>: f& f1 u! p" k; L' s
<P>with ODBCDirect, and different servers will recognize slightly different </P> * q" M* a0 k. ~6 w8 W<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> ^& ^8 W% P6 F1 s<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> ( D% Y+ M. L: U; e& D0 Y% b<P>included through the Help menu. Be sure to check the appropriate reference </P> ' p" K1 G# }5 l3 C$ {<P>documentation for the SQL dialect of your database server when using either </P> |& K4 h1 ?0 j1 b3 _
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> , @- n( t9 D5 C* J( R2 Y<P>client/server applications. </P> U7 s. }& M" E4 Q1 J
<P> </P> ' ^" @+ ]4 n5 ^<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P> ( a# S$ K: L2 @( w" K<P>trap changes while two or more users are editing or deleting the same record. </P> e* W% J) e8 |: `& @9 \( O5 A2 P
<P>For example, if two users start editing the same record, the first user to </P>2 s b9 V c+ p, j$ M
<P>execute the Update method succeeds. When the second user invokes the Update </P>! g2 `$ O j& u5 Q
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> . D4 }$ I1 |1 E! L+ q<P>the Delete method to delete the record, and the first user has already </P> 1 J) ^. }, I7 z: b2 L<P>changed it, a run-time error occurs. </P> # [# y7 s+ ~; p7 Z/ a<P> </P> 1 }0 i+ m) o5 p7 H# q& ^& c7 K<P>Typically, if the user gets this error while updating a record, your code </P> ' l) B+ H2 w& r# y) [# H5 o' m) s<P>should refresh the contents of the fields and retrieve the newly modified </P>2 O3 m* p, o" B
<P>values. If the error occurs while deleting a record, your code could display </P>3 C7 s8 `8 ?- }' p7 K+ S& x; @
<P>the new record data to the user and a message indicating that the data has </P> : A% M& O" G; _5 {/ W: }9 X3 a; n2 ~<P>recently changed. At this point, your code can request a confirmation that </P> - i4 R9 W! g! q: b) C/ h( h9 ^<P>the user still wants to delete the record. </P> 8 [% P8 Z7 `6 g$ V<P> </P>! J1 s, p* J1 D/ s& q, |7 K8 }
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> y) m. W1 |( ~9 s! R1 j! K& }6 l
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>- ?2 X6 M# p6 C! P' B- g
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>5 Y: d, e" |6 s) ~
<P> </P> ! P1 B; J' @* n# j. W, a% G<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> + s) y1 i# K5 ^# A<P>the dbRunAsync constant in the options argument. This allows your application </P> - {2 m7 v- V& Z8 @0 F& J j<P>to continue processing other statements while the query runs in the </P> $ H$ U5 s% u* K: k' v! {& ^( G) \<P>background. But, you cannot access the Recordset data until the query has </P> ) V* b3 h k# L3 P<P>completed. To determine whether the query has finished executing, check the </P># x& f& y% j+ O
<P>StillExecuting property of the new Recordset. If the query takes longer to </P> $ t* ^% m& \* A3 [/ H* \<P>complete than you anticipated, you can terminate execution of the query with </P>, d+ |1 h6 S- r3 X) F* ~
<P>the Cancel method. </P> ( u5 X+ }3 A) I+ l( D, }<P> </P> 2 A/ r8 T8 ~2 B) A<P>Opening more than one Recordset on an ODBC data source may fail because the </P>. }9 N6 I; }$ s* v h
<P>connection is busy with a prior </P> " y7 y6 m6 a) D3 n* V% j H<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>4 Q' J8 C! p; _! P
<P>ODBCDirect, if the server supports this. Another solution is to fully </P>7 ]+ o' |5 }% S5 ]1 C: g2 w* E
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> ' S* x1 C# w1 |& q. a: `<P>is opened. </P>) _4 i, G `1 |8 f( u" a) o0 S) u- C
<P> </P>( O! z( J& Q$ M
<P>If you open a Connection object with DefaultCursorDriver set to </P> 7 c5 N; |! A+ l<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>1 W; V) q- G, P1 S# U
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>, F p" ]. d: @% ~
<P>h in the lockedits argument to enable update caching. See the Update method </P> + u% i- N+ R7 E) m; U' c, j<P>topic for details about how to write changes to disk immediately, or to cache </P>) M5 _; Z& |. k2 N, O" ^
<P>changes and write them to disk as a batch. </P>. }4 L2 k8 }- x. E& p" U9 l
<P> </P>1 U' `7 i; {( P: Q5 `
<P>Closing a Recordset with the Close method automatically deletes it from the </P> 3 ~) v, W5 v( D3 ~0 g/ j' D5 Y" o9 I2 p3 W4 x9 g
<P>Recordsets collection. </P>$ Z j5 ^8 s* a! x& C5 |1 b
<P> </P>! B$ O4 ^+ r$ {" u( b" Y/ {
<P>Note If source refers to an SQL statement composed of a string concatenated </P> 8 x: u+ v; R8 v6 e: E<P>with a non-integer value, and the system parameters specify a non-U.S. </P>. p% K( V/ E8 p4 B5 h
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> 7 i: [& \, t) C$ F<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>, Y+ T1 {2 ? T' v6 o" |. K I
<P>Recordset. This is because during concatenation, the number will be converted </P> / y* w# I) D; A<P>to a string using your system's default decimal character, and SQL only </P>& y0 b# R' e, y! c: w8 h
<P>accepts U.S. decimal characters.</P>