<> </P> ! \' ~" a* Q/ e+ U* z- k- {<>Creates a new Recordset object and appends it to the Recordsets collection. </P>8 m9 H( x) h2 g y. M
<> </P> - v4 E7 w4 ^4 y0 c<>Syntax </P>9 a4 y1 c; M, Y( t1 t
<> </P>' l# _+ H4 N; l$ g/ d: s5 t" a
<>For Connection and Database objects: </P>) t# @! O! P: W3 A7 l$ \; c
<> </P>% b5 ]. N' s, I. r; n# O
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>5 @3 c- }! X( G" [/ g
<> </P> . I# B- Y- n) Z5 H* C. K. m. e<>For QueryDef, Recordset, and TableDef objects: </P>$ n/ |" O1 E: A; D+ B( H: F3 R
<> </P>$ P/ s. `* E* Z
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>& F* `3 U% Y# B% v/ f) W2 k
<> </P>0 p# g9 N( t$ R8 n7 `/ y$ H
<>The OpenRecordset method syntax has these parts. </P> . w# ~4 ]( f- V' S<> </P> 3 e: m) f- Z5 b3 W7 f o<>art Description </P> 3 H2 C1 E7 T) b<>recordset An object variable that represents the Recordset object you wantt to </P>2 ]8 v; v) r+ e8 c% Y1 I+ d
<>open. </P>& o; k7 x+ n2 Y8 `
<>object An object variable that represents an existing object from which you </P> 4 u4 [ i. x4 B3 }- d<>want to create the new Recordset. </P> . a4 u2 W2 o% `. k2 s<>source A String specifying the source of the records for the new Recordset. </P> + S' K7 P" W% ?$ A4 h' t9 f# W<>The source can be a table name, a query name, or an SQL statement that </P> ; c7 @, X7 k# W0 v: }3 |" [<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>! q% n' y% H8 j9 \" ~7 L" A
<>the source can only be a table name. </P> . C( V. m+ T+ A t$ ]7 ?<>type Optional. A constant that indicates the type of Recordset to open, as </P> " V/ }" N+ g' ]. @* {- V! _<>specified in Settings. </P>" i! \4 Y. C0 }! w1 b3 X4 p
<>options Optional. A combination of constants that specify characteristics of </P> , v, X0 _% Y4 M2 v<>the new Recordset, as listed in Settings. </P> 9 a/ Z4 I) f* A$ W2 Q<>lockedits Optional. A constant that determines the locking for the Recordsset, </P>$ Z/ c" k7 K$ K5 G
<P>as specified in Settings. </P> 0 N; w- X7 j) S0 f<P>Settings </P>$ u* _: q. _" l: E! A3 ]: _) R9 J, @
<P> </P>4 ^( ~$ M/ h* Q* a3 z: s0 J
<P>You can use one of the following constants for the type argument. </P> Y5 G$ F: C3 L8 g: ]( `7 B' v$ z$ h
<P> </P> ' C, w1 P2 P8 u; {0 n! o/ W<P>Constant Description </P> 9 M1 E' ~1 ~. d<P> </P>. G( B' p$ k* R2 m( ~ F
<P> </P> / U2 H3 ?8 Z }; v- B% }% E8 h<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> 9 Z+ H, _$ ^$ h. ?% Y+ i z<P>only). </P> 9 P0 B+ a% \' k& J! T0 T# ^<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>! t4 Y! _$ |0 R3 G
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> , ^1 I# E1 T8 i<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> " {# \& ~2 c7 i2 m: `<P>ODBC keyset cursor. </P> & i0 d# p5 w) m; i5 w, S<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P> 9 T6 ~. _. B2 f<P>ODBC static cursor. </P> ( @# ]% l* ]; F' c; B' @<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>4 G% b8 ^; M' H: F0 T( ?6 p
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>( B) T9 i6 e1 o3 k8 I
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> " u: P% I# n" O<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>7 d& T0 h) |# @4 J! L, m$ F' Y- T9 s
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>, @4 h+ {% A6 C, C
<P>y. </P>: |" N6 Y4 E1 p9 @6 }1 f8 z, T
<P> </P>0 N }$ m! O9 v6 N! b
<P>You can use a combination of the following constants for the options </P> / R; h+ u8 `- D* C, e<P>argument. </P>2 J. A' \9 j; n4 b. j) z8 K
<P> </P> & w$ [* G; n6 `) X% J' E& r+ C<P>Constant Description </P> * F% ^, J2 e# c, i- ~ u T<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> % M/ r# X; O+ U8 P$ T, P<P>prevents them from editing or deleting existing records (Microsoft Jet </P>5 o; N! X2 N* b& d# Z4 e: m
<P>dynaset-type Recordset only). </P> 2 u; _7 V$ V) @; x. x6 P; |* f. N" `<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> * S: o/ l D K/ i( ?0 Q, n<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> P9 k c, Z0 y# i9 q* \<P>dbSeeChanges Generates a run-time error if one user is changing data that </P>1 j& ^* O$ h" s4 A4 m8 ~
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> & D7 N3 E3 d. d' e: K% ?/ ?<P>useful in applications where multiple users have simultaneous read/write </P> ) x" O, H% d e7 p) Z: L" @8 F. L! g<P>access to the same data. </P> - `( S3 \. t+ w; E; h5 q<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> 1 K# q9 {+ E5 X5 Z" b+ ?/ o6 ?. I<P>Jet Recordset objects only). </P> 9 b2 }4 z( `$ q8 G- Y* \<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> ( {) ~4 ]( ~) \% K) ] f* r<P>table-type Recordset only). </P> 6 I1 r; [ @ Q* H8 T$ y6 t. a3 h<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> 6 V: H3 u5 O0 Q q9 v<P>Recordset only). It is provided only for backward compatibility, and you </P>4 s& w5 J' r* i3 e
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P> / m6 H! a# S; V<P>using this option. </P>" k I/ R/ ^3 h$ }, Z5 N( Q
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>+ S3 w# s' V: s `/ k7 s7 B
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P> ' I1 N a8 o& {1 M<P>option, which is provided only for backward compatibility. </P>: n! [% y4 \3 n* ? L' H
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>( Y r" o& L( P$ y# l% d
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>4 g3 A, J7 L5 p" X) O k
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> 4 j) {- j) I+ ~( w<P>not opening a Recordset based on a parameter query. For more information, see </P>8 N, P- F" a1 d# c* U5 I, ]- g
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>% L, M) g/ P. O' S! W; |
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>; o ~% g: Z3 h0 C/ U( s5 R
<P>snapshot-type Recordset objects only). </P> ' ^% j* F6 p y, ~0 d<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> ' t9 _4 \3 x) l' c" E( G<P>snapshot-type Recordset objects only). </P> 1 r0 z2 }1 a3 C& @9 z0 b( X! I<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P># M$ F6 z* V: d1 r, S
<P>and using both causes an error. Supplying a lockedits argument when options </P> ; T' A! U3 m/ w<P>uses the dbReadOnly constant also causes an error. </P>/ K7 l, N' H% W$ g/ \
<P> </P> 2 f8 C& X! c7 b<P>You can use the following constants for the lockedits argument. </P>/ x! n" w1 m6 k7 o, ?- q( K3 r
<P> </P>2 `7 b0 T4 H7 ]: X2 D9 Q+ ~
<P>Constant Description </P> 4 V, h1 D8 {2 ?. b: {<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>* o6 ^' z& t+ W, W
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> ' t4 h& J q, ^4 o$ i" H<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> ; f; }# o. R) }' g- D: n. u! U<P>run-time error occurs. </P>4 M/ G. t) r+ }8 f
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> . I8 G+ b6 D r<P>the Recordset in a multiuser environment. The page containing the record </P>+ y$ y4 e0 h3 g, n' Z8 x: z
<P>you're editing is locked as soon as you use the Edit method (default for </P>; i* v. _3 Q t, j
<P>Microsoft Jet workspaces). </P>6 t. m# G. w( W& l2 L
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> 9 q0 \) r7 i- L! i& ^<P>Recordset in a multiuser environment. The page containing the record is not </P> 1 a: u+ A" T0 i, g8 t3 Y<P>locked until the Update method is executed. </P># _' l! F1 Q- ?- w w9 r' `
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>8 X! C d6 k. S3 e4 b4 G# s1 D6 m \
<P>workspaces only). </P>5 P+ f7 a) D1 e; o- ]3 f( }- F+ T9 a
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>/ w$ g. E9 l) Q1 l
<P>only). </P> 7 ?" h9 d* ^: [) k- {<P>Remarks </P>) ?* }% W; L* a# ?7 W8 h8 j. Y
<P> </P> 3 b) y& Z6 ]* ?8 d# r<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>6 X: G, \* a V, _; S5 K: L
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>: Y W2 `3 z9 p/ e t
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>. v- p: v: `6 c: L) F' y0 D
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P> # d. N; W i E! F& E {. d. W j<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> ! y# S2 z3 X: a1 p$ B, N<P>data source, you must first set the Connect property of the linked table's </P>1 A% ?' r4 k0 J0 }. V5 A
<P>database to a valid ODBC connection string. If you only need to make a single </P> ' S* N1 z9 E% J0 [3 R+ d2 I<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>! j* J) q, y) X2 }0 @4 e
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>+ [# B$ }$ Y5 ?- L
<P>argument. </P>/ C f2 U1 t# V1 s8 R* i
<P> </P>: K& X3 f1 b: ]/ W5 S6 B
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>0 w$ f' N$ r2 v- r; v/ ?0 Z2 x
<P>is of the same type object. If object </P> 4 X. x7 r7 P2 H6 x3 j+ y<P> refers to a table-type Recordset object, the type of the new object is a </P> ; a/ K" ]" C3 N) w+ t<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>6 G2 N9 z$ M1 g$ c1 D5 k
<P>杢ype or ODBCDirect Recordset objects. </P>$ d9 H; w8 a% t; k/ o
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> . `& E: U* F9 P) c<P>select query in the source argument, such as </P> " r1 I4 q$ u3 Y6 l% H( v4 q; R<P> </P>5 h0 m9 y! y% i. `5 d8 Z" F, L
<P>"SELECT LastName, FirstName FROM Authors </P>: X( w" l& j- Z% q9 B" Z0 q
<P>WHERE LastName = 'Smith'; </P># z/ \2 n% \$ J; B: ?+ p8 z
<P>SELECT Title, ISBN FROM Titles </P> ' I4 K/ G1 N$ y! Q* H2 k. x5 p<P>WHERE ISBN Like '1-55615-*'" </P>* U& j' d2 w# a( @. U
<P> </P>; u- b9 A! v7 b# D& K @
<P>The returned Recordset will open with the results of the first query. To </P> * U* t& F) ~+ ~0 }1 K) B) F<P>obtain the result sets of records from subsequent queries, use the </P> ; J g) |7 S: ?2 j3 b( R' t/ ]<P>NextRecordset method. </P>( P+ u! X( G7 L/ J% v, N
<P> </P> 2 ^. r, ?- T) L<P>Note You can send DAO queries to a variety of different database servers </P> : }0 w" r7 C4 k% V, [<P>with ODBCDirect, and different servers will recognize slightly different </P>- v9 G% `2 A- i- s% W: B$ `- Z
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>7 [5 B7 \- x- |3 f" }( ]
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> $ p: H- Z" T" ?<P>included through the Help menu. Be sure to check the appropriate reference </P>) _+ o# C5 v+ f
<P>documentation for the SQL dialect of your database server when using either </P> 8 F1 o. ?, H ^4 H, O% p0 w<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> % S4 l W6 w7 Z5 S<P>client/server applications. </P>- m# m- ?' k( \; p
<P> </P> v" m5 g( w+ m. `( Q0 A3 \3 I
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>) ` p/ x% S6 p; G4 q
<P>trap changes while two or more users are editing or deleting the same record. </P>5 {* Z& ]9 v4 o/ P) I4 D
<P>For example, if two users start editing the same record, the first user to </P> : X( k7 r8 w3 [5 O, V. C+ V8 Z<P>execute the Update method succeeds. When the second user invokes the Update </P>' J( s2 B% l2 ]/ H* K4 ^( i @
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> - F! E% R- d. s' I' d<P>the Delete method to delete the record, and the first user has already </P>/ s7 x; R9 g8 Z
<P>changed it, a run-time error occurs. </P> : g: K0 p+ ?& @- |* O. a8 F; D<P> </P>( {; N: ]3 {* Q0 V
<P>Typically, if the user gets this error while updating a record, your code </P> 4 b5 B* o7 M7 h- v1 F<P>should refresh the contents of the fields and retrieve the newly modified </P> p: S3 P2 ]: U6 G! u9 ~) d
<P>values. If the error occurs while deleting a record, your code could display </P>/ i6 T+ G0 j7 J* E% s2 d5 H
<P>the new record data to the user and a message indicating that the data has </P> $ R" j8 E9 `9 G% [0 Y& g, p* z<P>recently changed. At this point, your code can request a confirmation that </P>0 P5 C* b# J. r E1 n9 H/ {6 _/ V
<P>the user still wants to delete the record. </P>, A& P( t" U2 ^! w; `! L+ r
<P> </P>7 P; R/ r0 R. S: w* i# X5 E
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>5 |, Z* I( j4 o) |# `/ F& r
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>( B0 H; V$ O4 ? S. s& N
<P>later) table that has an IDENTITY column, otherwise an error may result. </P>! t" U" F4 `* u$ ?% ?: g- y6 L. f
<P> </P> $ [% |6 R% C1 V; Y& M. H1 {<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> * ?0 X6 U* I1 J+ R4 F<P>the dbRunAsync constant in the options argument. This allows your application </P> [. T! f I/ ]1 \<P>to continue processing other statements while the query runs in the </P>+ F2 x5 F) F, \$ K' [& V) T+ K
<P>background. But, you cannot access the Recordset data until the query has </P> . z. S" N8 Z' u( Y8 |" ]<P>completed. To determine whether the query has finished executing, check the </P> 2 k: q+ |9 Q7 l3 ?4 W<P>StillExecuting property of the new Recordset. If the query takes longer to </P>6 F: t8 V( d; a) o% c6 B0 I2 r
<P>complete than you anticipated, you can terminate execution of the query with </P> % ?! ?2 W4 }' v<P>the Cancel method. </P> / [0 {+ j9 }1 E0 O5 h<P> </P>! I) G! _! H" o2 r, z8 Y, v- H' b
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> ( q, `# I! ?, v) I9 D9 z: n$ q<P>connection is busy with a prior </P> ; j0 s/ Q! p/ T# w* z, Q<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>0 D$ M1 e+ ]/ H- X7 a/ S; t
<P>ODBCDirect, if the server supports this. Another solution is to fully </P> 9 q) n! X8 s4 k5 L, t1 ~+ c0 }6 Y<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> # ?$ Z) B5 N: W% n. g' Z/ D<P>is opened. </P>! E0 M1 K8 y$ E- p3 S/ h* I7 d/ Z
<P> </P> % B, }. V& s- u% z- Y<P>If you open a Connection object with DefaultCursorDriver set to </P>% h& H, H: r, Y- k( h
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> 7 n4 b& L, |( @. ]9 Q<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>4 s4 X! \! L2 E' \# \( b# k- |
<P>h in the lockedits argument to enable update caching. See the Update method </P>- W, e& H6 Y1 ^% o$ W( [8 g
<P>topic for details about how to write changes to disk immediately, or to cache </P>+ l8 Q2 E# i3 F2 A/ i: z& g
<P>changes and write them to disk as a batch. </P>% f3 q$ ]0 Y$ O& s$ f0 i
<P> </P>" f {5 e8 ?2 P/ E! q5 J# H6 ^- F
<P>Closing a Recordset with the Close method automatically deletes it from the </P> 5 A0 j/ j3 \0 @) B$ R0 q2 E+ j# J, I
<P>Recordsets collection. </P> 6 Q2 p# g1 w ~! B4 l5 U- n3 a<P> </P> % M& U+ T7 U+ y6 i, k& L. l6 r<P>Note If source refers to an SQL statement composed of a string concatenated </P> 9 U# \# Y4 b2 F<P>with a non-integer value, and the system parameters specify a non-U.S. </P> " J- |% F( I% v<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P>0 E; G4 x4 _( `
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P> : B5 c; ^5 `* |5 k7 o q$ a6 y<P>Recordset. This is because during concatenation, the number will be converted </P>; v: A( k3 Z5 \( B1 ~ Y# l( l
<P>to a string using your system's default decimal character, and SQL only </P> ' R/ [( s2 O& F" q, T4 N<P>accepts U.S. decimal characters.</P>