<> </P>3 J$ o0 {/ \8 o9 E* V
<>Creates a new Recordset object and appends it to the Recordsets collection. </P> ' t$ L9 s7 r4 ^<> </P>: n% u& `6 Q/ ~9 x
<>Syntax </P>9 G: V: Q. C2 A0 F
<> </P> + Z) R, ^5 i6 ] M<>For Connection and Database objects: </P> t4 t$ N! t+ n) t+ Q/ w9 g<> </P>% `( b% R+ }5 |2 d
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>3 x4 E7 h3 A [# ]" M& h
<> </P> , J. q/ T' `) _; C4 z) F& i<>For QueryDef, Recordset, and TableDef objects: </P>" K8 v( n! d# \' D+ \- A
<> </P> & ?" [- ]& G0 H5 j<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>) p/ p w5 v3 h; z
<> </P>9 Z$ X" u) k$ {( ^
<>The OpenRecordset method syntax has these parts. </P>, b! p# R# e3 j
<> </P>& O6 m) z0 r) Q5 f4 H% }$ m5 T
<>art Description </P> 6 Y( P$ Z ^% [: @<>recordset An object variable that represents the Recordset object you wantt to </P>2 B9 u+ u" |) x6 L9 t
<>open. </P> ) j" _# T, \9 F4 _, {<>object An object variable that represents an existing object from which you </P> " q2 u* k0 ~. E8 z0 w _3 m+ b<>want to create the new Recordset. </P> 6 q, ~, i% `( z$ L& q<>source A String specifying the source of the records for the new Recordset. </P> 9 x" X$ [" Q8 O5 z* w5 f<>The source can be a table name, a query name, or an SQL statement that </P>' u6 L3 _. p, U7 m
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>9 W# i1 V, {& O: _" C
<>the source can only be a table name. </P> 0 o+ X. q) @* Z( M8 i<>type Optional. A constant that indicates the type of Recordset to open, as </P>5 b( [9 S- U% b! F8 O# f% n
<>specified in Settings. </P> " O( H% ^) B' T2 l# D3 S, O<>options Optional. A combination of constants that specify characteristics of </P> 3 A! V# O+ ?. H<>the new Recordset, as listed in Settings. </P> 0 S7 l: A; A3 N; Z: ^<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> 0 [) h; R/ f' H9 w1 c5 i6 `<P>as specified in Settings. </P>0 V! Z9 `8 z1 G g+ K: t, a
<P>Settings </P>$ o% A. ~6 [2 P: Y, ?
<P> </P>2 v% Z/ m( C: f i) X
<P>You can use one of the following constants for the type argument. </P> - d# J! e! C h% H8 t+ \3 X<P> </P>% G" `9 _ i% z9 `. O
<P>Constant Description </P> 3 Y1 [- R! Z, Y" D3 B& q5 Y x<P> </P> 9 k2 G+ o. i& O! K* J6 J$ C5 q<P> </P> + \+ g) {. N9 ?, u<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> & e8 J* ]# T- U9 Z<P>only). </P>. f7 u/ [2 m V. e) ] K0 V1 H/ A
<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>( @ z: @3 [3 S" s9 y
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>7 q$ r( l# C1 @* i9 d+ w' v! P4 n3 F3 R
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P>7 a. I4 W* x( @0 {/ @( n3 Q
<P>ODBC keyset cursor. </P> $ Y" z& l: R/ h8 A' S. E3 X<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>0 e/ z/ B- |9 e
<P>ODBC static cursor. </P> 9 C4 H6 _+ o9 e. P( l) E% `<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>& T z1 O# b. B# _; {
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P>0 f' o3 [- Z; p% O# b
<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>% E& k) Q6 i3 T) l1 o
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>, Y. i/ _2 v# U, ?5 l
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>& ?3 g' ]8 x6 \1 f d9 A$ g
<P>y. </P> / \6 F, S3 Z+ v' z3 u& W2 x i<P> </P> ! E6 E% [$ \" w0 E7 L( Q1 _7 e2 Y<P>You can use a combination of the following constants for the options </P>/ A* D- b5 a+ q6 l m/ b
<P>argument. </P> H# R( o1 ~6 J1 P<P> </P> # b4 O5 T6 Z- Z5 v8 K% n<P>Constant Description </P> + `7 X' [8 b3 p- J1 u- ~3 X: P+ g<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P>9 w7 N& l+ r6 A+ L1 s* j
<P>prevents them from editing or deleting existing records (Microsoft Jet </P> ! k5 \0 {# v8 q B4 D7 ?<P>dynaset-type Recordset only). </P>* c1 x; }) q9 D: E
<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>+ ]& }6 ]8 r# b
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> + m- a. L$ D$ t+ v% ]1 O<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> : G/ o, y' h) M4 J<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> ( q- G: w9 o- a& M<P>useful in applications where multiple users have simultaneous read/write </P> % Y# m* y: L5 v<P>access to the same data. </P>' D# l/ y' P' [2 P3 \- Z
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>" Y8 b# m1 q) ]$ d0 j6 Y$ y
<P>Jet Recordset objects only). </P> * U b, ~: h0 H% c a<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> 5 d4 Z( I W8 d) a" C: {<P>table-type Recordset only). </P># U9 l7 _3 O, m* D' c. z
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> 5 z; }0 w$ Y" K/ e<P>Recordset only). It is provided only for backward compatibility, and you </P>9 E( [5 A) p! T- \* q1 O( |
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>4 c+ v7 G; x) p7 N# ^4 S8 z6 I
<P>using this option. </P>+ P, q6 b; N5 o+ @8 ^
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> + `# j7 `# G' f1 u, _; Y<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>8 ]# O1 b' P/ [; ~: _
<P>option, which is provided only for backward compatibility. </P>1 [: C& X4 Q0 P9 m8 k) ]$ T% Z
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P> 6 U( B/ V: t) E# g<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> / B- }) |. Z! F9 ~1 c9 y* y5 J: z<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> & l% P2 J1 e# v% \" D# |<P>not opening a Recordset based on a parameter query. For more information, see </P># i G+ x7 b# U3 V' |3 _* n
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>. n) h* ~0 @& x3 B1 ~
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>( k2 S* }7 ?# h/ P9 ~
<P>snapshot-type Recordset objects only). </P> + [1 {. e& a' ]$ d<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P> & l$ P1 { u* Q' C$ }<P>snapshot-type Recordset objects only). </P>! O5 A/ \: L- G) A/ i( M* W! y1 u2 Y
<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P>; v# I* z. }: \3 n5 S
<P>and using both causes an error. Supplying a lockedits argument when options </P>8 r0 G3 M7 P3 }
<P>uses the dbReadOnly constant also causes an error. </P>! R" g9 s$ q8 R8 I8 h+ o0 o# d
<P> </P> ( p( U# |! U$ S9 `! M( o! }<P>You can use the following constants for the lockedits argument. </P>3 z" U/ U4 s# e# @+ \
<P> </P> 6 W3 b% [) O5 M5 i<P>Constant Description </P>6 B: }' H { u1 g, _% ~3 w* n
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>5 M k: q6 {" L( D( G8 Q; n- [/ }
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P> , D/ Z8 X! b+ o8 K<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>7 e( D+ H# Y% ?
<P>run-time error occurs. </P>7 o9 ~. t) k6 ?/ Y9 U6 ~
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> ! t. M8 ^7 h5 f<P>the Recordset in a multiuser environment. The page containing the record </P>$ K& N( D! i' c8 n
<P>you're editing is locked as soon as you use the Edit method (default for </P>( n) p6 J9 _- D4 A3 `
<P>Microsoft Jet workspaces). </P>0 w. S' N- Z& k1 v, l8 z2 N# I+ Y
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> 5 }4 |6 m( a; i" P |( X9 i<P>Recordset in a multiuser environment. The page containing the record is not </P>7 y1 g2 a8 o3 m# U! ]( |% |
<P>locked until the Update method is executed. </P>6 C$ _4 B8 F9 ^% ?; S
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P># \# {+ J0 P1 T: f0 w
<P>workspaces only). </P>; K- K7 g0 a! _; E9 [8 X( J
<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> , L! y$ _: A0 N+ u<P>only). </P>) [0 O7 s& Q8 M; B1 q, R
<P>Remarks </P> 3 ~8 o- n: Z i6 ^3 Y/ j" T$ `<P> </P>2 a! g) q, n9 x: ?
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P> + Z- U g7 S& l! |5 g3 N) S<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> 5 Q. A( H2 {" ]4 `% t<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> ' p1 q1 O& `6 _9 f" D6 m' L<P>the type argument; if you do, a run-time error occurs. If you want to use an </P> 5 {6 {5 ~! a9 ?& R3 v<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>/ i: t$ n( V' w, W- k6 G7 k
<P>data source, you must first set the Connect property of the linked table's </P> # S+ g. z7 B/ [5 K. N<P>database to a valid ODBC connection string. If you only need to make a single </P> 3 |/ m* q9 L' m6 j0 V: c<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>8 n- f! p2 M1 S5 j" @. j5 e
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P> ^! L1 k# g8 r& T
<P>argument. </P>% A6 J! y, m) k1 t# Q3 k- V. i; i
<P> </P>7 g! G) d6 G# c Q
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>9 c" j" t l+ h0 y( j
<P>is of the same type object. If object </P>- ?& n! ?& b6 G4 t5 ?6 H/ ~( e M9 s
<P> refers to a table-type Recordset object, the type of the new object is a </P> $ q8 j* d2 l1 J7 F% i5 `<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>4 d5 X3 T' c! I* P) [; V; a) ?
<P>杢ype or ODBCDirect Recordset objects. </P>2 E# H, v9 Y$ g2 B- a* @
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> $ E# I4 v e# i( Y6 @( q' Q3 o<P>select query in the source argument, such as </P> * Q4 X+ S$ g# }<P> </P>8 H. x% B( L5 ?) Y
<P>"SELECT LastName, FirstName FROM Authors </P>* n' z' G7 g4 |1 M1 H4 n5 F
<P>WHERE LastName = 'Smith'; </P>; Y0 t( r) a2 Z; o
<P>SELECT Title, ISBN FROM Titles </P> ) R2 O2 t1 t1 @/ b+ |& n<P>WHERE ISBN Like '1-55615-*'" </P>! T6 G8 }+ }( U* @) K3 h+ `6 a
<P> </P> 8 X9 f# V' L8 h3 _) c<P>The returned Recordset will open with the results of the first query. To </P>1 b7 N' O1 I$ d# Z& }
<P>obtain the result sets of records from subsequent queries, use the </P> 4 i; S! A1 x; m" o<P>NextRecordset method. </P> ; |) f* l `# Q' q. M, X<P> </P># N4 k+ j1 N3 C: }; A; H
<P>Note You can send DAO queries to a variety of different database servers </P> ; O! y% v; l( P<P>with ODBCDirect, and different servers will recognize slightly different </P>& _! V3 t+ S9 @9 k. N9 y4 `
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> ( D! i1 w+ B! q4 J+ L2 j% j<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> ; {9 _! l% M0 s3 C- G<P>included through the Help menu. Be sure to check the appropriate reference </P> : }; [9 N; f: D2 A {0 k% _<P>documentation for the SQL dialect of your database server when using either </P> : M& x( s0 B4 T7 Y4 o<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> ! A6 `8 V0 R4 p; F, h<P>client/server applications. </P> ]; I! U% Z* ]& U+ a( P( M- t# Q- I* r
<P> </P> $ ^2 k. ^2 {/ V" f<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P> ( K. C- b6 D- F<P>trap changes while two or more users are editing or deleting the same record. </P>0 R A! `1 S/ D) e3 v" N+ u+ a
<P>For example, if two users start editing the same record, the first user to </P>0 t6 m0 p3 Z2 r, r6 v( F
<P>execute the Update method succeeds. When the second user invokes the Update </P> ' @& k9 H9 w, Z! M+ A/ T b<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>4 c! B$ g( J* _+ L' s9 }
<P>the Delete method to delete the record, and the first user has already </P> 0 U& l2 H: x( V5 l<P>changed it, a run-time error occurs. </P> / o6 h5 ]; X% `<P> </P>% q' d4 t1 Z+ z5 M, x7 j
<P>Typically, if the user gets this error while updating a record, your code </P> * R0 I8 L) j; ]<P>should refresh the contents of the fields and retrieve the newly modified </P> 8 O7 t# e8 m4 P0 B/ g* K<P>values. If the error occurs while deleting a record, your code could display </P>+ F" S( D- u$ j& v+ L0 l+ R$ T5 j
<P>the new record data to the user and a message indicating that the data has </P> 1 S5 Z2 w$ B9 c( D, ~5 P<P>recently changed. At this point, your code can request a confirmation that </P> ! I' n, S! J1 F' h<P>the user still wants to delete the record. </P>! S2 w9 A' ]# @
<P> </P> / `% ]# C2 A" Y<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> ' J. w+ H: c2 h) Y; |<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>' s) ?9 _+ N8 j+ G- I& d+ R
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> + Y# Q$ o+ Z- ]* i' `( m3 V0 R<P> </P> & h) c2 X6 o" Q" a5 u! T<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>6 L6 V) `+ M- j" k5 X( i! N
<P>the dbRunAsync constant in the options argument. This allows your application </P> " D# J$ N! r/ A/ J3 _<P>to continue processing other statements while the query runs in the </P>5 a1 d- O4 u7 D+ |
<P>background. But, you cannot access the Recordset data until the query has </P> 2 n1 J! T. O# ~8 N3 }<P>completed. To determine whether the query has finished executing, check the </P> % ~5 \; z! s8 ^4 r2 g# c<P>StillExecuting property of the new Recordset. If the query takes longer to </P>6 q, [1 Y( E) Y5 u9 z
<P>complete than you anticipated, you can terminate execution of the query with </P> ; J7 G/ E% ^" ]0 V<P>the Cancel method. </P> 9 s6 ]1 k2 ^5 n4 H2 ~3 m& \<P> </P>- L9 r: F `3 k a! n" b
<P>Opening more than one Recordset on an ODBC data source may fail because the </P> " A3 @4 S3 V6 c% w" G<P>connection is busy with a prior </P>8 _$ Y' `* }! r( ~- X6 A
<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> 1 z3 ]! J% m6 M. u% o& j<P>ODBCDirect, if the server supports this. Another solution is to fully </P> M; Q0 h' U8 n6 S+ }, s6 r* t<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> % t9 W+ t; p3 B4 y4 U+ l4 h<P>is opened. </P> $ t E+ P* z b) r<P> </P>% u' @! i" m( R$ ~5 n
<P>If you open a Connection object with DefaultCursorDriver set to </P>. l1 V* I* V# `) M) y, I
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>. y% V3 d3 q9 p
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>) x; i( [$ R& M& ], z
<P>h in the lockedits argument to enable update caching. See the Update method </P>3 J( B5 x5 s& L3 A; C
<P>topic for details about how to write changes to disk immediately, or to cache </P>8 n3 T$ A& c' o; G% c* |5 @ r
<P>changes and write them to disk as a batch. </P> ( ^' k/ m% \; D5 U) J<P> </P>* `6 f# f/ T* l2 a
<P>Closing a Recordset with the Close method automatically deletes it from the </P>$ u* z: i; g) @
" r$ j, U8 t- ?' J<P>Recordsets collection. </P>' p6 o A7 g: T9 M" |- y) m( `" ?8 Z1 ^
<P> </P>, {( D0 `- A X: k
<P>Note If source refers to an SQL statement composed of a string concatenated </P> 3 A! s- K2 `' D) d$ j0 ~<P>with a non-integer value, and the system parameters specify a non-U.S. </P>, n4 Z2 P: o( e) h5 m* o
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P> / }# h; l H( U8 @' s2 q' X<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>: P2 d, t( D" D/ K! `% [
<P>Recordset. This is because during concatenation, the number will be converted </P> , n! f) J% E% [. i- U! E" c<P>to a string using your system's default decimal character, and SQL only </P> " G0 d ~9 k$ Y% D5 D2 r<P>accepts U.S. decimal characters.</P>