<> </P>/ p$ F$ F# v4 A. c- K" [
<>Creates a new Recordset object and appends it to the Recordsets collection. </P> 2 \, K5 f" v& M) Y<> </P>, E/ B; U6 F" ?7 m) \7 `
<>Syntax </P>* G$ s, @( e9 I9 B8 c8 Y; U4 E N! H
<> </P> 5 R" \4 e& j& `, ?: @8 b0 @2 l<>For Connection and Database objects: </P>7 k' Q- s, p1 F) ]+ x% ~' e. h; n
<> </P>4 ^' N$ q" k8 |
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>9 a& s( `8 i8 L, ^
<> </P> ; H7 ^# @! C3 w7 ]. E2 Y8 ~7 _8 R9 L<>For QueryDef, Recordset, and TableDef objects: </P> * _' O6 Z+ t$ q+ T8 @7 x+ V<> </P>; `% I% T& r! Q. @
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> ]' q3 X/ C2 M* y9 b) V% _& M0 Q' o+ b% }<> </P>1 t2 N# o v( I* K
<>The OpenRecordset method syntax has these parts. </P>2 A9 p$ F/ \3 Q0 _/ P+ }
<> </P>, s/ i8 u+ ?3 l$ E) C
<>art Description </P> 6 |9 T- d4 L5 I8 j! l<>recordset An object variable that represents the Recordset object you wantt to </P>8 f$ x8 h8 c* V& U" ^
<>open. </P> ' Y" s" i5 M8 u, o6 d<>object An object variable that represents an existing object from which you </P> 0 X& \) x; B9 I! v& B& X- \# l8 u! u<>want to create the new Recordset. </P>$ b. e7 _1 M1 q: X
<>source A String specifying the source of the records for the new Recordset. </P>7 C9 }- e/ W1 k/ P/ s6 c
<>The source can be a table name, a query name, or an SQL statement that </P> 5 M8 }0 C8 i4 r$ B- E<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>' D G5 j! w7 c# j+ L _
<>the source can only be a table name. </P> + V) Z0 S$ c/ r' ~<>type Optional. A constant that indicates the type of Recordset to open, as </P> 4 E6 K1 } f. s. A" T3 t/ \- A<>specified in Settings. </P> . c: T) N! z% s) Z<>options Optional. A combination of constants that specify characteristics of </P> # }0 s B+ O2 G# _' |<>the new Recordset, as listed in Settings. </P>$ l' t# v( e) a6 m3 Q( {% L* G, {
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> 1 T! b) B$ L' d3 w<P>as specified in Settings. </P> $ b: f, N6 X! M* ?3 N; R<P>Settings </P> 5 |" M A0 e$ Z/ _" ^3 Q7 J$ ?+ K/ ~<P> </P>! Z# ~) j8 ?1 y8 E4 \
<P>You can use one of the following constants for the type argument. </P>! @$ c6 p0 X2 ~; |
<P> </P>1 L9 a' j' f6 t8 l( y4 j; j
<P>Constant Description </P>6 M, c7 c' O, {5 r8 y; D9 P6 K1 B- ]
<P> </P>7 b* g! Z0 L0 q' |
<P> </P># a; s. N% n0 L2 _* J9 u
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P>" ]% j1 \" _) z8 ?+ d# C. C0 ^
<P>only). </P>" P% m! y" _2 p6 g' v# K1 `" j
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P> : L( p* D& C( z. E' V8 e<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> $ j$ M. {- A; Q, k5 H3 @<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> 4 |! o- N$ i* T! {$ o. {4 l6 Q( H) v<P>ODBC keyset cursor. </P> 8 ] F6 z# u7 f: ^4 e$ n<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P> 0 y0 {+ U. ?+ k8 q$ {8 J<P>ODBC static cursor. </P>4 |+ a# |: [- H3 l/ d- z3 N _4 ] q
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P> U0 _) c) m( c<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> 0 f# P6 A- R O3 V! [' m5 W<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> * Z7 p5 p+ b* ^<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>" Z8 j: G0 v, W/ U
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>8 B! y6 o# P* A$ ?% Y
<P>y. </P>7 Z: f. `* m4 s! g( `+ I+ E( e2 U: N! n+ n
<P> </P>4 z5 L K; n) X4 A8 y
<P>You can use a combination of the following constants for the options </P> & A1 T& X# N0 @7 d: u8 q<P>argument. </P>! ?, d) j# _0 C1 b+ |- o. l6 b
<P> </P>& Z7 s; t. R6 q6 B. Q, y
<P>Constant Description </P>2 \( c/ w6 k3 M' v" [1 M8 {# e1 s' R
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>) b @6 L7 F1 {) z7 [
<P>prevents them from editing or deleting existing records (Microsoft Jet </P> " k' T& ]# _# C; }<P>dynaset-type Recordset only). </P>; K( f1 I3 a5 I5 Z
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> : T, V( ^. n* ~* m5 F- Y! ^<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> / X/ o( i8 [$ D' r, E<P>dbSeeChanges Generates a run-time error if one user is changing data that </P>5 Z( x+ I* _; w7 e7 F( B. M
<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> " k$ J* ?: P" x2 @<P>useful in applications where multiple users have simultaneous read/write </P> 5 r" o$ G9 Y( G/ O4 D4 b9 X7 A. I<P>access to the same data. </P> 7 W) q) C- `; W, Q<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>" a& l" \1 d& s6 F
<P>Jet Recordset objects only). </P>' |: J, U; G3 j5 z% K2 \
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>; B0 e* x" Y7 Q3 b
<P>table-type Recordset only). </P>- b6 q2 f3 F3 r
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> ( h" h; i2 D8 _% i# f7 r6 {<P>Recordset only). It is provided only for backward compatibility, and you </P> ( M9 ?' a0 o4 T4 \& Q; d# O: b<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>5 T' j9 c( @) |0 B; i+ R$ z @# T
<P>using this option. </P>" a( j1 [, Y0 P- Y+ a `+ `) E
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>8 M) ?( g" {- A9 T/ G) K" r: O
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>8 B* s( L- {& \! E
<P>option, which is provided only for backward compatibility. </P>& `7 N9 ^2 d6 g; ]# V
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>7 t! I! n4 V8 ^$ H3 F2 Y1 G
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> , V, C, f- u6 B<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> / d0 @7 F# O. u5 b/ n<P>not opening a Recordset based on a parameter query. For more information, see </P> 3 W' W8 Z/ N7 Y1 Y, q+ Z7 {8 U<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>5 |* u2 d/ Q$ [+ @. G$ p# d
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>- P. `8 |( ~% q0 E0 f' d: z
<P>snapshot-type Recordset objects only). </P> * T5 s4 J7 ^' J' _8 o, X' U<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>3 c2 n, `, d1 x/ K0 \ Y
<P>snapshot-type Recordset objects only). </P>) r; }8 @* `& v' Z# p6 ?
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P>/ r/ y( a& O% F6 A j
<P>and using both causes an error. Supplying a lockedits argument when options </P>. S* @6 N; L2 `
<P>uses the dbReadOnly constant also causes an error. </P> 9 c( {& ]1 V) X4 n3 {1 m- \<P> </P> 4 s6 d a& ?) i+ O) O/ g<P>You can use the following constants for the lockedits argument. </P>. I% h$ l- u6 x0 R/ w5 ]6 w. l+ B
<P> </P>+ u+ u; Q& ~- e% d9 B0 r( M
<P>Constant Description </P> ! n0 I+ X( c! n6 Z. }5 I" |<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> 0 a t! r/ Q; M( C5 [<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> 0 G' m2 p3 o9 u<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> : b' i1 Q, T, R/ {<P>run-time error occurs. </P>* A7 n4 p$ K1 t0 N
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>/ o* Y) s7 h: Q8 H
<P>the Recordset in a multiuser environment. The page containing the record </P>- y0 t0 g2 ^% o1 _& x/ X
<P>you're editing is locked as soon as you use the Edit method (default for </P> $ C. p1 w7 I4 N8 w<P>Microsoft Jet workspaces). </P>! N* V& }/ {6 o: R
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> 0 I1 }1 r2 z% {7 _6 Y `. r<P>Recordset in a multiuser environment. The page containing the record is not </P>; E5 F$ L: p' Q0 b' T" M v
<P>locked until the Update method is executed. </P> ! ^! b0 R2 g1 s9 L5 f<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> , c& i/ Z5 i" S" _<P>workspaces only). </P>$ H0 Y; V8 ?& {( Z
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> 8 j: i8 \5 v( i9 f3 ~( c* Y<P>only). </P> 4 _/ q1 X5 X1 s# M<P>Remarks </P> : X" v: Q" J2 {; A6 k) V: S<P> </P> 2 j9 w t/ b$ W- ?, T: k7 {7 J5 j<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> - s' p$ d5 [ F& Y0 I8 X- T<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> ) C# p: i/ ]0 T* u+ c2 l9 J<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P>* x# a9 X* f; R4 `; D) {7 u
<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>; B: k! p3 f: s" e2 ^% D* }
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> ! Y5 N4 i# ?& B5 v% f+ a, s$ b<P>data source, you must first set the Connect property of the linked table's </P> ) P0 p4 Q/ t& E6 t1 _+ Y" ^% D& {<P>database to a valid ODBC connection string. If you only need to make a single </P> ) o. C2 g( Y, A. F<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> " j( U" X9 g8 D) c3 L) y+ e' O<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>: z( W9 L3 T' n5 _$ o7 h- I/ M' w
<P>argument. </P> H/ m8 t. A* x<P> </P>2 w# J4 r* |# Y, A" Z, S0 Q" A
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> & W; H+ \. j8 \% H) R' @<P>is of the same type object. If object </P>, x' H P1 ^8 v( K% v
<P> refers to a table-type Recordset object, the type of the new object is a </P> - _; g x* Y2 E<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> H \# ~) `; z; i<P>杢ype or ODBCDirect Recordset objects. </P>+ p3 Y3 ~! r b7 _: P, b; i
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> ! J% b" a9 E5 t1 d( S<P>select query in the source argument, such as </P>) j: s. M7 ]& `8 E. _ @
<P> </P> " ]! c* Z" `/ T3 `' R) Q! z1 n# Q<P>"SELECT LastName, FirstName FROM Authors </P>& t8 }! {2 p$ N3 }
<P>WHERE LastName = 'Smith'; </P>* t0 Z/ r. p$ ~ t
<P>SELECT Title, ISBN FROM Titles </P> 9 O. t/ }6 I$ K; Q8 N3 q<P>WHERE ISBN Like '1-55615-*'" </P>3 z z( |. u j; i0 l6 p. p( b3 s
<P> </P> 8 `$ ] ]+ c A<P>The returned Recordset will open with the results of the first query. To </P>* Z x7 ^; a1 n4 k# _; s! [" c1 i# b
<P>obtain the result sets of records from subsequent queries, use the </P> ; e: ~1 {3 f/ `) R<P>NextRecordset method. </P>9 ~( y5 x' H) o5 A! S7 O q0 A
<P> </P>2 s& o z9 \# Q9 }5 O* [2 O
<P>Note You can send DAO queries to a variety of different database servers </P> , \) }8 U! n8 h; P5 J, h6 {<P>with ODBCDirect, and different servers will recognize slightly different </P>2 ?+ W4 u& S: j* n
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> ( c$ T7 k4 V' G$ d* Z<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>2 b4 J; L8 f; n% J, G
<P>included through the Help menu. Be sure to check the appropriate reference </P>. I n4 h' I6 z! W& u, s3 ?
<P>documentation for the SQL dialect of your database server when using either </P> # ?8 c2 d( [7 |* Y% a<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> R' _) |( B7 |6 Y<P>client/server applications. </P>/ k. h" y. @9 e: F9 W+ n0 k) G- \6 K
<P> </P>. ^. w# x# a8 y5 E
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>) [& L. n7 P' D& i5 V4 v
<P>trap changes while two or more users are editing or deleting the same record. </P> + k) A* a( P" \6 s<P>For example, if two users start editing the same record, the first user to </P>' E% L6 h! N3 O& L+ O9 @3 |
<P>execute the Update method succeeds. When the second user invokes the Update </P> & n' g, s6 m- M+ W/ F+ x h" V<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> 0 P% ~% z' B5 R) R8 n<P>the Delete method to delete the record, and the first user has already </P> # X8 N/ c, E$ h8 H; w+ d<P>changed it, a run-time error occurs. </P> & o" e6 i9 h& z1 C* d2 ?<P> </P> # b3 y) x, e# _; X8 V6 f, u<P>Typically, if the user gets this error while updating a record, your code </P> ; ~6 n v4 A" i% u7 A<P>should refresh the contents of the fields and retrieve the newly modified </P> : F9 ?8 I2 i5 k/ u9 G9 d9 q<P>values. If the error occurs while deleting a record, your code could display </P>6 [ @: W7 }" X8 s, z1 G
<P>the new record data to the user and a message indicating that the data has </P>$ N: x4 A0 ~4 Y0 t1 }
<P>recently changed. At this point, your code can request a confirmation that </P>! `! _% N$ o% D; a! s5 l
<P>the user still wants to delete the record. </P> Z& f9 S7 o% v; _* M+ R5 N7 O
<P> </P>$ {$ I& x. c4 Z' U/ ?8 Q
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> 6 z4 M: e0 g9 I# d- J4 j" z9 }- G" C<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>& A: s! P! I. ^3 R
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> ! @; @% n6 m8 R<P> </P> g! P" ?( v$ l- ^1 p4 _<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>& m3 O1 x! m; F1 n
<P>the dbRunAsync constant in the options argument. This allows your application </P>4 C5 ~- ~: b* Y9 h4 s7 i1 D0 ]
<P>to continue processing other statements while the query runs in the </P>4 R# `- t/ w7 a# E& _$ \
<P>background. But, you cannot access the Recordset data until the query has </P> 3 \ u3 ^) \* ^$ ], M% v<P>completed. To determine whether the query has finished executing, check the </P> 3 W% v* c% k! k B2 i8 {<P>StillExecuting property of the new Recordset. If the query takes longer to </P> * ]' `6 u8 p5 l* m<P>complete than you anticipated, you can terminate execution of the query with </P>3 h0 n6 K% U; @1 B+ k, x. N
<P>the Cancel method. </P> $ `5 C7 Y. M- C6 K% K @<P> </P>6 U: F5 {, ?0 l
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> ' k: Z- d. s. n; q$ Y<P>connection is busy with a prior </P>; R6 y" B! _8 z1 O9 {
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> & k* i% \7 Y, S, R<P>ODBCDirect, if the server supports this. Another solution is to fully </P> / {& b+ f1 J4 s3 z A( s; |9 X<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> 1 `. b0 X% Y8 b6 ]: f3 l* G( m<P>is opened. </P>3 Y* z8 b/ {; u' Q
<P> </P> " Y* k& n: L F' F<P>If you open a Connection object with DefaultCursorDriver set to </P>9 I$ m$ G, j) J' d: i9 X# l" x2 w x
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> % l! \; }, @* G9 C" O* T. T9 R" O; M n<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>. j6 N( K, B: G
<P>h in the lockedits argument to enable update caching. See the Update method </P> 2 x* B/ z0 u, |6 h<P>topic for details about how to write changes to disk immediately, or to cache </P> # Q+ q1 L9 Q2 n1 O6 k; O8 ~<P>changes and write them to disk as a batch. </P>- S; {' m W+ a8 X
<P> </P>, y, B: W u; p6 T7 k
<P>Closing a Recordset with the Close method automatically deletes it from the </P> ) b. j% u5 } y4 g 3 y a) I7 N* N4 \" U<P>Recordsets collection. </P> 3 t- e1 w1 _# s( @ d<P> </P>: |1 C' e! z& {( ~1 `5 u
<P>Note If source refers to an SQL statement composed of a string concatenated </P>+ a% R a0 I8 E3 I
<P>with a non-integer value, and the system parameters specify a non-U.S. </P>2 A! V7 {$ A* B* @9 V5 l4 C
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P>) s0 \! k2 ?1 _3 G7 c
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P> . E* d- h4 p' R2 B- W<P>Recordset. This is because during concatenation, the number will be converted </P>$ g; a6 I% Y8 L
<P>to a string using your system's default decimal character, and SQL only </P> ! D+ N. Q: {7 |) {<P>accepts U.S. decimal characters.</P>