<> </P>* a& v0 d- ?& ~" |# k
<>Creates a new Recordset object and appends it to the Recordsets collection. </P># t' x( K: x1 d4 H
<> </P> 4 g- V, I+ M8 s3 i. J% Q) i- i<>Syntax </P> & t" M1 e+ D) g" q<> </P>. w6 d, m+ K" {: \9 X B9 I& t) P3 |
<>For Connection and Database objects: </P> 6 p5 o" O3 N' c% m<> </P> ) Z% F2 p3 C! x9 Q<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> 5 {; d" D2 u" }( r; u3 s. |# }<> </P>$ Y' Z, A' @" o. q5 u g/ v( L
<>For QueryDef, Recordset, and TableDef objects: </P>$ d( u: V1 i0 \# N
<> </P> ( X/ J9 T$ s. f K<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>. G# B: y3 S6 @; T
<> </P> % C) R6 u) p% s' ^4 }<>The OpenRecordset method syntax has these parts. </P>8 [* B! ^" b0 g' i$ |% \- G
<> </P>/ W. j6 R, d/ {6 Q0 g! {
<>art Description </P> # l1 C6 x& s0 r$ P<>recordset An object variable that represents the Recordset object you wantt to </P> 5 V% R+ x4 W& H& {' i<>open. </P>+ l# L' M4 n8 x( R
<>object An object variable that represents an existing object from which you </P>/ m7 ]7 f* Z+ u% ^
<>want to create the new Recordset. </P> 1 v; M) [" s- D1 V R3 z8 T' R4 \<>source A String specifying the source of the records for the new Recordset. </P> 7 T& z0 t7 R2 x5 X<>The source can be a table name, a query name, or an SQL statement that </P>3 G+ H- g$ q# C) X0 Q. R) E
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> r: M! V0 q+ |1 n( u) v1 }
<>the source can only be a table name. </P>; K2 Z/ I2 C* [8 X1 D1 X6 I C7 q
<>type Optional. A constant that indicates the type of Recordset to open, as </P>- N: P! U E# K1 d
<>specified in Settings. </P> d; H, ^" Z( f
<>options Optional. A combination of constants that specify characteristics of </P>' c+ V2 b" Q2 Q" |: S7 O$ i
<>the new Recordset, as listed in Settings. </P> 5 s5 @" P! Y( G7 M f& \<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> 8 r. P7 _ |8 P& g8 I0 g; [/ z<P>as specified in Settings. </P>: c8 y+ ^: R: @2 W* E) X
<P>Settings </P> % O* m9 c7 Z. B' g<P> </P># A; {, F" E$ M, [( M( ~2 }
<P>You can use one of the following constants for the type argument. </P>" d ] @( M/ b2 T
<P> </P> ; b( i# S" q8 C3 h<P>Constant Description </P> / b8 q( g' Z* h# r8 B, r: J% U" _<P> </P> ?9 E4 H& X6 S3 i2 p B% ]<P> </P> 9 I) K' [* g4 _) o9 e<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> 2 R6 A" q2 N$ w" b<P>only). </P> 0 D, L: m. x0 V( B<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>' u/ f4 S; c4 e
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>: T% T0 j# X/ I- I
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> + ?- w7 a( ~' O( F<P>ODBC keyset cursor. </P> & @/ V" _) j* ~6 }<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>; E* ^4 x& y. X& A* g' j
<P>ODBC static cursor. </P>8 @! d4 K ^ K
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P> 4 }8 {) o2 g- O3 _2 U<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> / G& P" u1 m' G2 n+ [% k% c. d<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> $ l$ ~% _* B- C e0 ^' v) J<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P> 1 ~1 w1 {. o& ` O# C<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>& ?! F% `; o8 t6 U8 d6 X
<P>y. </P>* t) x* m4 f! q% U$ X' T
<P> </P>) ~9 J$ s8 g9 B# x- b. M$ W8 M
<P>You can use a combination of the following constants for the options </P>7 r. [5 e. S6 Q5 r! B
<P>argument. </P> . z# |) I; O6 Z' Z3 [<P> </P>% E6 l! C y2 Z6 z& |
<P>Constant Description </P>( W1 m; `0 z) ]; s( A; Q
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> 3 @: _9 S, e/ a# U, a" U5 M8 c<P>prevents them from editing or deleting existing records (Microsoft Jet </P># o* E4 i1 [4 i% u8 `
<P>dynaset-type Recordset only). </P> / b- y Z4 [: t% c4 x3 T& m<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>- n2 A6 r/ ]4 z- {" n
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>, l4 }) p& ^6 @2 I4 g+ b
<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> 3 V) h9 P8 u) O<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> 7 @$ v) Y; ]8 ?: C* g. A; e- @<P>useful in applications where multiple users have simultaneous read/write </P>: j k# _% m) X! d, ]/ l& W V
<P>access to the same data. </P> " C2 {& S( j4 b% J9 J t% h<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>3 B+ E1 Z' B& a$ f; B
<P>Jet Recordset objects only). </P> - x) {4 Z: Q0 O! B4 K<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>& f2 @" e- z$ ?2 ~
<P>table-type Recordset only). </P>' r) P. G( `1 \5 M8 J$ c) s
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>* b* N$ h% U% Y' a
<P>Recordset only). It is provided only for backward compatibility, and you </P> 6 |7 \% Y- g4 C7 Y/ l3 u<P>should use the dbOpenForwardOnly constant in the type argument instead of </P> + V. [3 m, {$ @, K# T! i% j) S+ z<P>using this option. </P> . R1 P7 R# J% t7 O' C! [) O, B* p<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> 5 `/ \9 o5 Q5 n- W5 p<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>- c( Z* p+ y( k# Q# y7 z. V
<P>option, which is provided only for backward compatibility. </P> 9 ^! r- K0 A. G, c" t4 o<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P>+ p4 I# v2 }0 r1 p
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>6 H& ~: c, P3 w& R% ^: c
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P># c9 o7 C) P) h/ `. _0 e: B
<P>not opening a Recordset based on a parameter query. For more information, see </P>1 i* n' z6 A5 p/ b J
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>. k7 z2 @+ [% f* L" f9 n5 Z+ S
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> ( Z* h% ]9 K r6 Z' ^<P>snapshot-type Recordset objects only). </P>; R1 G3 |- b+ g# D
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> . O* h5 V/ R5 O/ K<P>snapshot-type Recordset objects only). </P>3 x" ?3 T4 W: R& y; j
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> 6 k) x/ S7 a' M4 {, p( z2 v: j<P>and using both causes an error. Supplying a lockedits argument when options </P> ! z. Z9 ?. V! ?' Y. N<P>uses the dbReadOnly constant also causes an error. </P>0 s8 [* p% M3 G5 Q+ y! ]
<P> </P>! T, {. b* {1 K: w+ m- D3 @
<P>You can use the following constants for the lockedits argument. </P>2 c, H2 r& G$ O
<P> </P> 0 u3 Y, R% r" m# ^ I& b0 c<P>Constant Description </P> ) R+ B/ X0 C5 f2 @<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> & v( L U; r2 R7 b; A<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> 8 x" ~5 G7 x. N* O<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>% n. X0 U" w, K+ V; `: H
<P>run-time error occurs. </P> % Q- [3 s0 s3 H3 {6 b' I<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>) a6 y- m! S9 a( ^
<P>the Recordset in a multiuser environment. The page containing the record </P> / G' y0 c5 U& X# b# J# b7 Z<P>you're editing is locked as soon as you use the Edit method (default for </P>! n+ }* o9 U- V
<P>Microsoft Jet workspaces). </P> - e+ p6 j: U/ I9 [, j& S<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>6 i7 \6 V6 ~8 Q+ n% ]2 b
<P>Recordset in a multiuser environment. The page containing the record is not </P>2 @! g8 t* i& k& R, H8 e& \
<P>locked until the Update method is executed. </P>* P. s2 W; R, b
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> , g5 S% s+ P/ K1 w8 R& \5 a) e<P>workspaces only). </P>: i; n' n. |7 A/ L) G* o8 R
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P>1 O1 I+ o& |# l' z& d
<P>only). </P> - l- D! C' Z8 ?& Z& B+ B3 _<P>Remarks </P>! B3 {, [- Y5 v) A1 c: N
<P> </P> 1 U# X1 J4 t: N2 _4 ?2 y<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>9 n! @ u/ F% A
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> * A" j" f1 T3 o7 U- C% w# P<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> 1 v4 n% W7 @9 B# e g- Y/ U<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>* G) [# _; H5 f& `, M; Z2 I3 |. E
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P># W/ k4 p* _4 ^+ @
<P>data source, you must first set the Connect property of the linked table's </P>; a# |* D* X9 j: N* Y2 s2 c& X
<P>database to a valid ODBC connection string. If you only need to make a single </P>" C' k3 }( E( C8 P
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P> ; a# w+ ^+ a% R% F<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>, `$ R! K6 d' B! `% K4 b
<P>argument. </P>0 y1 V: |" d0 x$ M
<P> </P>- x y8 C- n, `7 W
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P> `% D- R4 @0 w1 R0 N/ j<P>is of the same type object. If object </P> , @; \7 J" V& T* M8 ~. L5 \% U<P> refers to a table-type Recordset object, the type of the new object is a </P> 6 A# V* o4 h: j% S<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> ; k8 k# }. o3 P<P>杢ype or ODBCDirect Recordset objects. </P> 4 k$ l1 b3 j' I2 d0 p6 O3 m<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>- B* {" F& C$ Z, i- q% H
<P>select query in the source argument, such as </P>. o/ X/ L) z. R* Y& w/ L! ^
<P> </P> ]% E7 s4 g. c, H a
<P>"SELECT LastName, FirstName FROM Authors </P> : v" k: Z7 m+ Y4 r+ ~" y0 \3 _<P>WHERE LastName = 'Smith'; </P>; w8 }! v3 l& ~* o6 M y2 H
<P>SELECT Title, ISBN FROM Titles </P> * }6 z- G6 B+ _, B s: O5 b<P>WHERE ISBN Like '1-55615-*'" </P> 9 \; E8 c1 o: T; _. _! P<P> </P>) F7 o% B& ?9 |3 l1 v% s
<P>The returned Recordset will open with the results of the first query. To </P> + p* F1 u! G* _ E" ]! y<P>obtain the result sets of records from subsequent queries, use the </P> ' A0 g# L7 S. r% \5 Z<P>NextRecordset method. </P> 4 N( r6 m* l3 y, i+ ]/ @1 n<P> </P> - F! R8 n. D$ e& S2 z# q3 M; }9 m, O<P>Note You can send DAO queries to a variety of different database servers </P> * l' O0 l$ W' I$ @' Y<P>with ODBCDirect, and different servers will recognize slightly different </P>$ U# h- \3 [2 |) U" Q
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>! n& g6 s2 W8 l; N- p; Y
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P>8 x2 b9 z# u, N) v" o
<P>included through the Help menu. Be sure to check the appropriate reference </P> & u! V6 y6 M9 ~# G( U<P>documentation for the SQL dialect of your database server when using either </P>) ], N! v/ s( }, i" G4 v) r( i( O% S
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> " z. B% @) ^( v, O; I<P>client/server applications. </P> # s1 @3 {) ]$ c6 u5 ~5 ]& @: O<P> </P>5 [- ~" [1 h6 @ E6 ^
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P> / m6 ^3 l$ h9 x) N7 {<P>trap changes while two or more users are editing or deleting the same record. </P> . S) M3 J+ c& }' L! g/ k<P>For example, if two users start editing the same record, the first user to </P> . Z7 [0 J' `' ?/ n$ k<P>execute the Update method succeeds. When the second user invokes the Update </P> 9 M: P# r/ h; P<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>) i4 R0 A& j! P3 L6 {/ T
<P>the Delete method to delete the record, and the first user has already </P>* `) w9 G" L8 V- ?# r
<P>changed it, a run-time error occurs. </P> 0 x# ~* }0 z; i8 @ m7 u# K<P> </P>' o3 K. X5 y' i5 z
<P>Typically, if the user gets this error while updating a record, your code </P> . \0 D* @% X. R8 W! E0 m0 b9 P<P>should refresh the contents of the fields and retrieve the newly modified </P>* T) ~- k2 ~2 U# g W0 n9 y* M
<P>values. If the error occurs while deleting a record, your code could display </P> , B" j. f! U; B6 ]<P>the new record data to the user and a message indicating that the data has </P> # p' l# T4 I! f8 m<P>recently changed. At this point, your code can request a confirmation that </P> ( `) ], ?/ p. T8 Q; o/ V. S% D$ f<P>the user still wants to delete the record. </P> $ t8 ` \" e3 M+ a<P> </P> 7 I" ^3 X; y. [2 b0 x6 W( C8 t; n* Y3 T: L<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>3 w0 y" M/ W! V# T: R
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P> # C+ B6 K7 j4 x* g1 o/ H2 r8 G<P>later) table that has an IDENTITY column, otherwise an error may result. </P> , v# R. l6 Y; C* o: N<P> </P>$ t' d3 e' z$ j8 ~
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> 5 h0 U$ `! k# p# k0 F* q2 U<P>the dbRunAsync constant in the options argument. This allows your application </P> J3 C! P+ f& F* \
<P>to continue processing other statements while the query runs in the </P>; }8 y/ I8 g! p+ A/ N
<P>background. But, you cannot access the Recordset data until the query has </P> 7 F) ?# ~7 n& Q# i<P>completed. To determine whether the query has finished executing, check the </P>! ]# M' E0 G* [+ Y$ w$ E, ^
<P>StillExecuting property of the new Recordset. If the query takes longer to </P> ! K8 x$ V# |, u# V; x X<P>complete than you anticipated, you can terminate execution of the query with </P> 9 }) |1 h) {/ m/ N<P>the Cancel method. </P> " \ U9 q$ F& _5 s1 T7 i. O<P> </P> " Y7 Z7 c0 j, m8 c9 h! T<P>Opening more than one Recordset on an ODBC data source may fail because the </P>% w3 G7 |: `, A
<P>connection is busy with a prior </P>, s9 o9 B5 R8 c) v \5 r
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> & L8 E6 N9 z6 e9 U1 D; \<P>ODBCDirect, if the server supports this. Another solution is to fully </P>3 R, l2 F8 H7 U; ` b
<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> % c3 l1 _- s0 [' m3 G& |<P>is opened. </P> # L8 d: h8 v0 m8 |) ~" }. `<P> </P> " j: m! p. S) Q7 d: e9 u<P>If you open a Connection object with DefaultCursorDriver set to </P>2 m- B/ B ~1 c K* F+ \
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P> . W! M/ T W$ c u) ^7 A4 f<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P> ' }6 i3 U ]1 c5 |4 V( ]8 {<P>h in the lockedits argument to enable update caching. See the Update method </P>$ r/ H% a% }4 h7 r& \$ t6 _
<P>topic for details about how to write changes to disk immediately, or to cache </P>: c$ O8 E2 u; @* J
<P>changes and write them to disk as a batch. </P>2 [9 c5 k4 {# E1 L
<P> </P># F6 ^1 `/ _; Q* A
<P>Closing a Recordset with the Close method automatically deletes it from the </P>& v% M5 A. x- @) R
/ i3 g, o5 u4 L$ k' J% \) g5 I9 ^
<P>Recordsets collection. </P> + V- J% S& t5 x x' X% P0 I. B<P> </P>$ ?, b. m( u' `# s+ x% J1 |6 ?2 C
<P>Note If source refers to an SQL statement composed of a string concatenated </P> 6 a' j" Y, Z# H: K( O<P>with a non-integer value, and the system parameters specify a non-U.S. </P> # b. c- U. B* i& C. }" X, u6 {3 O<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> 1 |6 Z* T9 j( J* J<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P> 4 ?9 K8 o) E5 q+ I<P>Recordset. This is because during concatenation, the number will be converted </P> 2 J( x* B6 x( k( A: d<P>to a string using your system's default decimal character, and SQL only </P> % l8 c( C; h0 w' C<P>accepts U.S. decimal characters.</P>