<> </P>7 u( E, s& d8 x, E, }# A
<>Creates a new Recordset object and appends it to the Recordsets collection. </P> $ P+ C' S4 b" H9 L& n<> </P> % g3 j6 m# k# v<>Syntax </P>0 v& e3 c! j' g6 M: o1 m& g9 o; D
<> </P>3 p$ Q( a" x( l9 i% S
<>For Connection and Database objects: </P> - F# w! x$ \* H<> </P> 4 [' X* P- a, A' |: i1 c0 a<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> Z9 w+ {% t' O2 H: \% ^<> </P> : e R2 j8 Z* q+ {& p( Q( v<>For QueryDef, Recordset, and TableDef objects: </P> + f" b( y# \) k7 |5 H) K<> </P>6 ^" O! L8 P& g7 p+ ^0 u% p! H
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>- @. S2 I7 @; V; b& v
<> </P>5 |: Z4 T# f3 f
<>The OpenRecordset method syntax has these parts. </P>9 I4 ]. E8 G4 R* P: n: h* f
<> </P>& W5 C2 r( S& \8 G; [! r
<>art Description </P> 3 P `/ R, E2 W! n) R: S<>recordset An object variable that represents the Recordset object you wantt to </P> 3 ?/ ?- X S3 R; x8 F<>open. </P> \2 V9 Z8 b3 l0 s6 Z<>object An object variable that represents an existing object from which you </P>4 w9 P( h9 H0 `; y* V1 e- |* V
<>want to create the new Recordset. </P>4 L7 R& J2 J+ ?) L
<>source A String specifying the source of the records for the new Recordset. </P>& V. }+ L8 P! f
<>The source can be a table name, a query name, or an SQL statement that </P>9 y r# W" H8 o! ~% C
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> 6 S3 Q* z) R, Z( u<>the source can only be a table name. </P>) v4 Q- I- A0 E
<>type Optional. A constant that indicates the type of Recordset to open, as </P> 7 @ R' j' T# J" G<>specified in Settings. </P> ; X( z" y L j* d<>options Optional. A combination of constants that specify characteristics of </P>1 l. \; E- i1 K! b
<>the new Recordset, as listed in Settings. </P> : V; `; X% B& Y<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> & b; |) Z& H7 e. |4 l E- r' |<P>as specified in Settings. </P> 3 |' h8 Y8 L7 z, }( Y<P>Settings </P>5 l! w) y# h$ E1 V
<P> </P>' }3 Z) S5 ^! w7 ?5 M _
<P>You can use one of the following constants for the type argument. </P>1 O, _! Y8 U) M
<P> </P>" T( c% a9 V5 R; I6 P: L& w! Y
<P>Constant Description </P> + N, y/ N% Z% b" F2 k+ y<P> </P> 9 H1 a6 m% \( H6 H0 D9 k" H# o0 k<P> </P> / G" m5 U- @7 j: o<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P>: e7 u8 f: a; W
<P>only). </P> + t5 |" L, a" ?, k: v1 B$ z<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>8 z2 m' w) E9 C
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>4 E$ g' Y# z8 M9 E5 S% Y
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P>+ s, S, J( t8 j, Q
<P>ODBC keyset cursor. </P> 7 s+ d8 ]4 d, d$ t<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P># R2 T% I0 I1 m) _) t/ J+ L& t
<P>ODBC static cursor. </P>/ X$ ]4 i3 X, s& ]" Z
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>; E8 c2 }/ K1 h' N4 L
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> ; X$ J! u! Y- _! Q- y$ u<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> 6 _; P4 n1 B5 D2 q& M' M<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P> . m" f/ u' U0 {1 n! t9 b<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P> 2 I* b# D; Y. g<P>y. </P> + l" U* g& k+ H z2 \<P> </P>0 Z/ B$ M4 j e7 r3 }
<P>You can use a combination of the following constants for the options </P>- x1 A# |6 x+ J6 r
<P>argument. </P>/ [$ d; ?: U- P$ S: w8 d
<P> </P>: M/ x# b+ H1 |* N
<P>Constant Description </P>1 S% F1 q, @/ c# h: m
<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> ; T/ i7 y; Y3 |; x6 ~<P>prevents them from editing or deleting existing records (Microsoft Jet </P>1 W, w1 m. ~$ Z& \! }
<P>dynaset-type Recordset only). </P> ' b( w" Q& ^& B/ a$ T<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> F2 c; _& c% K) V2 a
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P>- Y- g9 S1 d6 w
<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> ; x, I; Q/ y K' ^<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P> 1 |& L" a4 k1 A9 U: M<P>useful in applications where multiple users have simultaneous read/write </P>- c9 ?8 g# s g4 m9 ~
<P>access to the same data. </P>& d8 m9 Y$ i+ \! Q1 B$ b
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> % C4 K: n9 s* k) J0 \, w8 J<P>Jet Recordset objects only). </P>4 F/ I: C; ?. P. {' j6 A; m; E$ [
<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P>+ f# |7 P+ C3 {* P
<P>table-type Recordset only). </P>, p# R! X% k1 W3 [3 |
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>- d' K$ P2 Y, w* v- Y- m3 \0 L, _
<P>Recordset only). It is provided only for backward compatibility, and you </P>. p5 \ X! {8 I: j" f1 X# Q
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P> & G: m+ |2 L7 }) b<P>using this option. </P> ) }) ?. @+ D9 \+ s<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>- D$ {& {& M* _2 w+ A: ^* |. V
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>" a" ~1 ^0 m. L1 q
<P>option, which is provided only for backward compatibility. </P>- V2 @, G8 C2 l/ V
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P> U0 z$ o" o2 Y1 q6 k9 n0 d
<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>- U; O* f+ V! r: |0 A" V0 `
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P>/ c8 j( q3 [7 p" n0 P3 a
<P>not opening a Recordset based on a parameter query. For more information, see </P>7 O( {9 b( N2 x b! M, O
<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P> * W( R, H6 W, Y2 y* h<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>( i" A9 i* _+ d
<P>snapshot-type Recordset objects only). </P> % R4 C3 |) F+ J<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>! C2 D$ E5 H" q
<P>snapshot-type Recordset objects only). </P> " F$ m; i I0 u2 F( r7 e& g<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P> 4 `5 V5 E* }0 J9 M, T2 Z<P>and using both causes an error. Supplying a lockedits argument when options </P>+ @' D! v8 q( ~" d( V
<P>uses the dbReadOnly constant also causes an error. </P>5 x7 @4 D5 }+ W: {9 Q% Q. b
<P> </P> 9 {- V' x Q6 S, E+ R<P>You can use the following constants for the lockedits argument. </P> 9 |7 t* D5 N/ C/ P$ {<P> </P># m* _" e" Y2 P( ~& s
<P>Constant Description </P> . C' f! Z* a4 V<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> 6 a+ k3 v' j7 L# y4 F! v# ]<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>: W; g5 M Y4 K3 J9 v0 |0 |4 P
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>/ a' S$ o' I" z& R6 C% b
<P>run-time error occurs. </P>' X3 s# X4 \& T
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> , x6 F( a$ w0 g4 E<P>the Recordset in a multiuser environment. The page containing the record </P>: d+ H! I0 I5 E, ]8 X- I7 A. f
<P>you're editing is locked as soon as you use the Edit method (default for </P> & b1 Q8 |+ q& z/ s$ E' v<P>Microsoft Jet workspaces). </P> ( h A6 {2 K+ A: M, F/ c<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>6 n& o; l ^; h! l+ d3 H' ^
<P>Recordset in a multiuser environment. The page containing the record is not </P> ' k& G9 X/ ?# {8 F {+ v) @<P>locked until the Update method is executed. </P> " }- B" N+ p4 J* N/ ~0 R4 u4 B/ z<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> . k; l6 Z5 i9 M4 ^# v% Y<P>workspaces only). </P> 5 b* X- q7 y, o4 D<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> 5 i6 @8 A- c" P. O) B* ~<P>only). </P> & o. u, {3 h+ w( |<P>Remarks </P>. k0 T1 p# U( K# @2 i* h( m8 h
<P> </P> ; H2 n/ e+ C4 _<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>0 _% l" ?, s4 A" K* a/ p' q; E+ T
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> ) F% h- r) x; W0 U# @& n. L<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> ) @( w; ^4 ~" e% e<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>7 y$ T: Q# l+ j7 O+ G5 i" z
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P> : h- c; \, y; w8 ]5 v" K! ], }<P>data source, you must first set the Connect property of the linked table's </P>" W0 _# \8 j% R) N) t9 O% t: X
<P>database to a valid ODBC connection string. If you only need to make a single </P> M2 X4 f- a$ v3 U, \( ^# J
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>( @ p/ X3 G$ Q9 c* l) @9 `% ~
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>' ~; N8 F! X6 I$ |
<P>argument. </P> % ?; D8 q+ u# g) K( D# N<P> </P>" Q& r# k2 w! u. C
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>. \" h) I5 p/ l4 P2 |7 F
<P>is of the same type object. If object </P> 0 `# I7 p, K# H k3 v! X) A/ u<P> refers to a table-type Recordset object, the type of the new object is a </P> - b4 B9 {6 C6 m7 _ Y* F4 a" e. [<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P>. ~2 p, J9 V; p* Z4 e$ ^) {
<P>杢ype or ODBCDirect Recordset objects. </P> $ j, i/ ?% h" b0 I<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P> % i% e) l! y0 ^; Q1 H/ B<P>select query in the source argument, such as </P>* D& I6 u' v' x; x {& `
<P> </P>6 m. y+ l9 E0 y+ ?0 d- O
<P>"SELECT LastName, FirstName FROM Authors </P> " t2 N$ K! V8 N<P>WHERE LastName = 'Smith'; </P>5 X& ~( D0 r' |; R1 J# Q) @5 A
<P>SELECT Title, ISBN FROM Titles </P> " |$ R! O- c% {- u, ]1 U' O<P>WHERE ISBN Like '1-55615-*'" </P>5 j, }4 Y0 q% {( @. m1 I9 i
<P> </P> 8 q3 o% t0 P3 c) K, |<P>The returned Recordset will open with the results of the first query. To </P> 7 x) J# O: @ V7 z<P>obtain the result sets of records from subsequent queries, use the </P> . |, g7 Z" X1 ~4 b$ L. }$ ?6 ]<P>NextRecordset method. </P> % t8 O3 [% t/ I: t+ m! e<P> </P> 5 F! B! C( ~- m* Y# `& P<P>Note You can send DAO queries to a variety of different database servers </P> : {- @6 A3 X9 J$ W1 b1 h" w<P>with ODBCDirect, and different servers will recognize slightly different </P> u8 k6 \/ a2 m) W3 I. ^
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P> / F7 N& a) h( J0 P0 s2 A<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> 4 F' D. r) w+ y6 S0 L& I1 u<P>included through the Help menu. Be sure to check the appropriate reference </P>" ^* \1 Q7 r2 I& K" z' G, ]
<P>documentation for the SQL dialect of your database server when using either </P> 7 B/ T3 ^% r" t( \<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> 1 t: m- K6 o H$ W<P>client/server applications. </P>& Y- {' Q! |1 R, z- N% `+ z5 o5 d
<P> </P>5 q5 @3 w* h; Y* H0 u) k$ C+ K% p" f
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P> ( U; b' G& E3 B<P>trap changes while two or more users are editing or deleting the same record. </P>- K, [# j- y5 L
<P>For example, if two users start editing the same record, the first user to </P> ' o( Z2 c7 b o8 d<P>execute the Update method succeeds. When the second user invokes the Update </P> x* [1 ^) w, D2 ^
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P>% _4 V- _0 c; t; u% Q4 {
<P>the Delete method to delete the record, and the first user has already </P> . `( k& g- |: Z; E5 _# I<P>changed it, a run-time error occurs. </P>& t* M& }0 Q+ E5 f
<P> </P> 2 ]* e" }+ N1 a; q! H<P>Typically, if the user gets this error while updating a record, your code </P>+ c' z+ U1 i0 K v D8 l
<P>should refresh the contents of the fields and retrieve the newly modified </P> + u* c* R3 K; [! t6 J<P>values. If the error occurs while deleting a record, your code could display </P> 7 u# E4 d( [/ a4 T% c8 C<P>the new record data to the user and a message indicating that the data has </P>2 p( Y9 \( ?" z7 s' I
<P>recently changed. At this point, your code can request a confirmation that </P>: b! m9 ~' w- u& M( k5 y' L
<P>the user still wants to delete the record. </P> 3 U: h: B: N$ P6 w6 U/ ]2 @<P> </P>6 ^& V( t2 v4 L+ N% R5 Z
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> `, i* l* L8 {( A
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P>6 N5 `. ~- d; C
<P>later) table that has an IDENTITY column, otherwise an error may result. </P> , D0 L- h3 _: b# D- b) i<P> </P> 9 u( F V. D+ l& Q5 _<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> G( n' |4 O4 k) \ z* Z: H<P>the dbRunAsync constant in the options argument. This allows your application </P>% ~" N2 q7 o5 |2 }: k
<P>to continue processing other statements while the query runs in the </P> ' [4 w$ ~8 ?; j6 `<P>background. But, you cannot access the Recordset data until the query has </P> . z; Z* V/ C& E3 L! W<P>completed. To determine whether the query has finished executing, check the </P> L* i: c9 p& L
<P>StillExecuting property of the new Recordset. If the query takes longer to </P>/ ^/ W! S( ]8 R! J$ d: ]
<P>complete than you anticipated, you can terminate execution of the query with </P> a8 i; d0 i) N9 |) m! [; [! J, @<P>the Cancel method. </P> : Z0 T: y- R6 M, I<P> </P> - L, \3 f- g: Q3 H8 w1 [' K<P>Opening more than one Recordset on an ODBC data source may fail because the </P>/ }0 }. N% r+ V4 V e" x
<P>connection is busy with a prior </P> ) J% G) m& K8 x; w, D+ E" f' p* S<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> % N, q9 g* V! l* P& @<P>ODBCDirect, if the server supports this. Another solution is to fully </P> 7 G* U# z( M8 U. w+ z' H<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P># p0 j, K& p/ N6 v' i
<P>is opened. </P> 8 E! g6 I8 `+ l3 p# R" u4 Q- G<P> </P> / Q7 g* @" O0 i- R$ w9 i6 J) v1 ^<P>If you open a Connection object with DefaultCursorDriver set to </P> + T* I% v3 M8 ~, q! q<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>) b4 h5 P7 d. Y* f; [: N
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>7 X2 z, [# r9 \9 ~2 Y( P. O" [
<P>h in the lockedits argument to enable update caching. See the Update method </P> 7 o/ e$ k1 a( ^. y: C<P>topic for details about how to write changes to disk immediately, or to cache </P> % Z" F$ I$ Q: ?, _<P>changes and write them to disk as a batch. </P>* X( J- \5 S }: ]
<P> </P> $ C p' y. t$ N' P<P>Closing a Recordset with the Close method automatically deletes it from the </P> 7 U2 F8 b! ?$ I7 T8 |- f7 ? " ^' |+ t. F' c6 I. N, G9 S<P>Recordsets collection. </P>3 ?3 P S* L* _2 N; T3 Y- H
<P> </P>3 P+ X2 f& A+ ~6 x* U
<P>Note If source refers to an SQL statement composed of a string concatenated </P> " _, J) @* y3 _( g9 f<P>with a non-integer value, and the system parameters specify a non-U.S. </P>: Q& v% s: Q$ A
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P>6 O0 n+ @5 p6 u8 ?7 ]* j8 d! `
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>- p! n6 o) @/ x+ _8 V3 v
<P>Recordset. This is because during concatenation, the number will be converted </P> 9 k: p5 m6 w' P* \% {<P>to a string using your system's default decimal character, and SQL only </P> ( Z8 `( y' W! L# @. ^1 K. B/ N<P>accepts U.S. decimal characters.</P>