<> </P>& H' u) j3 h O8 u5 m
<>Creates a new Recordset object and appends it to the Recordsets collection. </P> # P; E. `! {, W2 {) m/ [8 q<> </P> 1 J% Y& d+ ]! b) e<>Syntax </P> 1 f" G6 M' W! A, R3 Q) |8 w& c<> </P> ) g3 E- l8 s/ k7 g7 {7 y<>For Connection and Database objects: </P> & q$ A: W Q2 }) l$ O<> </P>* W. P( Y" c% g' U
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P> " C7 `- S, s1 m8 }<> </P> ' z/ U9 h# ~0 |: G<>For QueryDef, Recordset, and TableDef objects: </P>) w* O4 A( r: }% i u) I- T1 ^
<> </P>8 h, w3 P/ P$ e, C6 y$ u. P
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P>3 P; F! r* |/ k7 X3 B7 ?$ z
<> </P>+ t$ f; s8 f7 h0 `$ }8 ^- @, X3 k
<>The OpenRecordset method syntax has these parts. </P> ( U& x6 h* }1 L" C q' s. d4 G! [<> </P> / D1 c( E) E. u' t<>art Description </P> 9 B0 X+ v7 _, A3 h8 D<>recordset An object variable that represents the Recordset object you wantt to </P>( d" b& t8 a' ^7 F* n9 U
<>open. </P> & D0 F$ O. i/ R U' n7 q<>object An object variable that represents an existing object from which you </P>0 M& @! |% }6 [
<>want to create the new Recordset. </P>6 G. H+ {8 T/ ]4 ~1 V
<>source A String specifying the source of the records for the new Recordset. </P> $ v' q0 ~" I/ ~* c1 d" ^<>The source can be a table name, a query name, or an SQL statement that </P>' L7 W1 x+ ^' ~8 |
<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P> G) g" E" ^& O" B9 e2 W! ?! Y* T- r3 l, \
<>the source can only be a table name. </P>$ b. \# R4 h: r
<>type Optional. A constant that indicates the type of Recordset to open, as </P>: s% b. E* S7 ^: f
<>specified in Settings. </P> 7 N# {6 G2 E d2 b) r<>options Optional. A combination of constants that specify characteristics of </P>( y( d) ~. K0 f2 a4 z* D2 L& U
<>the new Recordset, as listed in Settings. </P> ) i9 o: [$ O8 p$ x! Q3 L) p<>lockedits Optional. A constant that determines the locking for the Recordsset, </P> 6 m7 r0 I* S2 M- M" Z4 A8 J<P>as specified in Settings. </P>1 h' k( f4 G0 D' E3 E
<P>Settings </P> / O+ H @$ {; h5 V. J2 o<P> </P> 3 S% {8 J8 b; N# Y- p) @% n% v<P>You can use one of the following constants for the type argument. </P>, U; c; r* b2 C$ z$ l. e, I/ Z( O
<P> </P> ( T3 ~2 x0 K, U+ v% Z D* e( r<P>Constant Description </P> , v$ X6 W9 @ M9 o" f* [% s9 r# M2 @<P> </P>) A0 l9 Q! \8 d7 D9 s9 d8 T
<P> </P>/ ?; i- w; z6 }% S5 I( v, k( M! U
<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> ; R" W) c a) A' H U<P>only). </P> 8 |4 h0 h+ {/ X7 i g$ \, K/ n<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>4 }! N/ y+ e4 a7 l
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P>) h. [! V! y/ w ^. ~* d
<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> * G* y5 d6 m' S: g<P>ODBC keyset cursor. </P> 6 q; A4 ]( e' E7 v( w# i$ f5 y<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>7 J' T2 Z2 a3 a! S, T% c3 ~( E
<P>ODBC static cursor. </P>( P: x6 O9 ~- @' ^0 A$ M
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P> , P, T8 [* ~4 P; Y<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> 1 V% h! i! C: \- C<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P> 9 W' D8 y3 W3 y& `5 m& G0 I- g: t8 \6 F<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P> 3 }( Q# }+ @0 N<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P> $ g+ B0 {* W0 ~, w/ m<P>y. </P> M/ Y: M; y: Q+ P0 R<P> </P>/ N! S4 x6 J* D( x2 g
<P>You can use a combination of the following constants for the options </P>2 K1 K- J+ N" {1 w& f# r
<P>argument. </P>9 w! Y1 p0 `9 `% ]
<P> </P> ' Q+ m1 n' e# f; O& A' t2 r0 k<P>Constant Description </P> 9 M( n( F) v% ?/ \* B6 B7 W<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> 5 v/ X2 u$ @+ Z" u/ K# q! r<P>prevents them from editing or deleting existing records (Microsoft Jet </P> ' {! Y" z6 Y) n( Q, I& @<P>dynaset-type Recordset only). </P> 2 z+ Z' r; c* ^8 |1 W<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P>' L3 ~: r9 `1 }8 W3 S
<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> 3 l( O5 u* d& j3 c7 O: L0 a. i<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> # C- x3 g+ |' K7 q* T! F8 N<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>7 P+ T# Z+ N9 W3 F: C; b3 a
<P>useful in applications where multiple users have simultaneous read/write </P> 7 @3 ~; e- y8 ~+ Y$ m$ T* E6 n<P>access to the same data. </P>1 h8 t7 ?. j' D: P8 [5 |( E" U) r6 W
<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P>% x, r7 Z- L" n" v' ?
<P>Jet Recordset objects only). </P> % H, y2 u) J0 v% |8 W<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> 1 _ x& V! ^$ d* v6 C! x<P>table-type Recordset only). </P> 4 Q& C* R) }: k+ q2 t9 b) p' A; }<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P> # m& N( |+ u8 u% e<P>Recordset only). It is provided only for backward compatibility, and you </P>- H4 _$ C$ C. Z- a
<P>should use the dbOpenForwardOnly constant in the type argument instead of </P>3 P& E4 q" M' i) ]
<P>using this option. </P> 6 m/ v) e) N2 n6 g<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P>* O- Y. ]6 v# |) Q8 r
<P>only). The dbReadOnly constant in the lockedits argument replaces this </P> $ x3 L4 e% n- J0 e) q5 U<P>option, which is provided only for backward compatibility. </P>& w. K B$ b; l1 P/ F1 R& S6 Q
<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P> - {' N2 @2 {1 I8 Z<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P> 2 J7 }# p2 o6 h, B! Y<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> " ^5 p' Q" |# v<P>not opening a Recordset based on a parameter query. For more information, see </P> % ~9 t$ h5 W8 O7 S8 C$ w<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P>4 K5 U9 R( _9 M* J. T
<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P> 9 K2 H1 x. u: L2 L" S% L7 g X" X<P>snapshot-type Recordset objects only). </P> 8 R% y: e: y2 N<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>/ j7 \( ~8 b; N9 |6 n
<P>snapshot-type Recordset objects only). </P> 4 q f* A# t% H1 q* y) |7 o<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P>5 W& r. l0 y2 X1 L* e \
<P>and using both causes an error. Supplying a lockedits argument when options </P> 3 D7 Y7 J4 J' ~<P>uses the dbReadOnly constant also causes an error. </P> / l' i7 X/ Q7 l; Y. j1 X) [3 L<P> </P> 7 D2 ^2 R, r0 M6 U! `4 d- }<P>You can use the following constants for the lockedits argument. </P> & |" Y& o4 U" b r( v<P> </P> 6 j+ x3 ^$ b5 V, A<P>Constant Description </P> 9 ~1 z0 w! ?% S* c) }& o) Q S<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P>& c5 d/ u* ^" T j1 ?8 M6 x \
<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>" ?! L" ]) E6 g
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P> $ j' r4 {5 Y k3 b( t<P>run-time error occurs. </P>* A3 u: p* S0 q7 u
<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P> : z6 ^+ k% L5 B: K' h @<P>the Recordset in a multiuser environment. The page containing the record </P> ' b% R, \0 Y4 }8 w# `) A<P>you're editing is locked as soon as you use the Edit method (default for </P>* Z+ G; ]5 b5 d* I: h
<P>Microsoft Jet workspaces). </P> * I7 B/ H% R `& @* n<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P>* E& [$ D5 Y4 @; Y9 ]8 s
<P>Recordset in a multiuser environment. The page containing the record is not </P>! ?3 j1 V3 \" N! L
<P>locked until the Update method is executed. </P> ) G% ]" Q+ ?9 t6 H5 R+ v; A! l<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P>4 U, }, r: {6 |: r
<P>workspaces only). </P> 6 k. L! C7 b6 h<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> + y6 U7 [7 r' _! E<P>only). </P>8 T$ n( Y' t, B1 R9 {; K# w
<P>Remarks </P> 7 @, g0 k6 B" N7 G" E% Y& n<P> </P>8 ~0 B. `2 J# s$ J5 g3 J
<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>* D' A4 p" J5 l" n. f( I$ ^: F1 y
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P>7 {* h/ p0 G- K
<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> 4 C* V2 W+ X; E' q( \<P>the type argument; if you do, a run-time error occurs. If you want to use an </P> % m5 G4 k0 d" ?8 {8 m5 i<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>1 t4 X/ [* e2 j. h
<P>data source, you must first set the Connect property of the linked table's </P>5 h; O# ]3 p+ k/ ?' e# ^$ C
<P>database to a valid ODBC connection string. If you only need to make a single </P>- H/ B6 [# C3 I+ Q% {
<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P># I! |) U2 G$ C$ C/ _
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>6 x9 t8 F& A( {
<P>argument. </P> & a, p+ K" O) r" X! p$ e<P> </P>) I2 @3 q% W$ \* L+ | Z* M
<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>% g/ Y9 _; m: G7 ?5 a+ m
<P>is of the same type object. If object </P>+ g( U# _; t8 C3 L' h5 p
<P> refers to a table-type Recordset object, the type of the new object is a </P>& b+ l: V7 f; [" ~' ~
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> - R0 m2 I4 Q6 P7 S; R# `<P>杢ype or ODBCDirect Recordset objects. </P> + K+ \# B& F4 M; G/ a3 i1 p8 R& n<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>2 J9 w7 ^1 u* s
<P>select query in the source argument, such as </P> 1 L" i& k( [; j1 O) q1 T<P> </P>0 e8 J# e! A8 l/ t$ f+ s1 C2 L2 M% m( Z
<P>"SELECT LastName, FirstName FROM Authors </P>. N7 o* ^% M( \5 n/ Z8 `0 Q: a
<P>WHERE LastName = 'Smith'; </P> 9 T1 ?& f# g# l<P>SELECT Title, ISBN FROM Titles </P> 9 E5 _; @- v- \<P>WHERE ISBN Like '1-55615-*'" </P>" c7 `, C2 {9 G/ j
<P> </P> # k. d" |% y" ?<P>The returned Recordset will open with the results of the first query. To </P> ) |8 ]8 _ o; v: _0 d$ ~5 O4 u<P>obtain the result sets of records from subsequent queries, use the </P> + h2 ?- C7 P+ x4 H$ c3 n<P>NextRecordset method. </P> $ ]4 ^- H7 ^2 Z<P> </P>! B: [) b' k7 H$ {$ H
<P>Note You can send DAO queries to a variety of different database servers </P> I. u0 g; v j8 F/ a
<P>with ODBCDirect, and different servers will recognize slightly different </P>5 P4 Z/ I# `1 c2 N
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>- L, c2 o, A1 l3 o
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> ; p+ A4 L! N6 q0 c/ O* t<P>included through the Help menu. Be sure to check the appropriate reference </P>( H& ^+ t( G |, R
<P>documentation for the SQL dialect of your database server when using either </P>1 Y' \: |) H, X. N) d
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P>8 W' L# v5 ?1 ~( S
<P>client/server applications. </P>7 B e: J$ V( h( f/ x3 S1 B
<P> </P>+ M9 O S9 G- X, n( z
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>, H& K/ M1 w1 }4 M6 g. k) W
<P>trap changes while two or more users are editing or deleting the same record. </P> 1 y8 F! P$ {5 |7 Q$ Z1 Z<P>For example, if two users start editing the same record, the first user to </P># ^* X$ Y0 d' p o
<P>execute the Update method succeeds. When the second user invokes the Update </P>$ R& l$ Q* m) F0 ?1 {2 O6 W1 ]4 p, u
<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> ' S& L$ U9 M% q5 C! I% X" N<P>the Delete method to delete the record, and the first user has already </P>. B7 F2 P. j( @; h5 ?9 r4 f8 }
<P>changed it, a run-time error occurs. </P> ) v( x' j5 o, M<P> </P>0 z0 v) Q/ F7 G; _6 h* }) C
<P>Typically, if the user gets this error while updating a record, your code </P> - U2 I/ C9 l* U' k, X' A<P>should refresh the contents of the fields and retrieve the newly modified </P> " X! ^9 O# C2 e0 T1 N<P>values. If the error occurs while deleting a record, your code could display </P> n) R& c3 s4 k7 Z
<P>the new record data to the user and a message indicating that the data has </P> ) l: r$ |. R% H<P>recently changed. At this point, your code can request a confirmation that </P> ' @* v; K/ g0 @) |: n<P>the user still wants to delete the record. </P> & I. E; R3 v2 o' e3 g<P> </P>4 d" p! J7 Q9 s# b) M
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P>, z" r7 _$ F4 y8 e. A5 |
<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P> : T: W+ i# E0 k7 Z- b6 K; q<P>later) table that has an IDENTITY column, otherwise an error may result. </P> 6 Q8 {1 `6 w. [. K- r' t# p<P> </P>/ ~% G0 A1 A" U
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P> . n: g. b) k7 ~5 ?$ v4 I& F) |9 m4 k<P>the dbRunAsync constant in the options argument. This allows your application </P>+ b- ] t' P0 h8 r" M
<P>to continue processing other statements while the query runs in the </P>8 N; l( h5 G& z! A2 R" Z( e. g
<P>background. But, you cannot access the Recordset data until the query has </P>+ d4 t& k4 l8 D4 P3 W
<P>completed. To determine whether the query has finished executing, check the </P> 9 s8 o, `: z/ u. }<P>StillExecuting property of the new Recordset. If the query takes longer to </P>' }2 }8 `, x+ l' B7 [# C. c: z% I" r
<P>complete than you anticipated, you can terminate execution of the query with </P> 5 H6 B" v; X n) a. f<P>the Cancel method. </P> 4 C ~% |5 L& X7 a' V<P> </P> . b. K# x; K9 C<P>Opening more than one Recordset on an ODBC data source may fail because the </P> # }9 `* r% B+ t<P>connection is busy with a prior </P> $ q3 u# A- l/ H' L. J7 m$ R5 L<P>OpenRecordset call. One way around this is to use a server-side cursor and </P> 0 W3 ^! d2 b* y" W3 j! {<P>ODBCDirect, if the server supports this. Another solution is to fully </P> 4 O" ]9 g1 s5 K, f& Y4 a<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P> 5 I6 E: Y- [* Y0 c g<P>is opened. </P> 7 c5 Y& Y2 W$ D0 r6 t c) r<P> </P>9 n! U/ A) B* m+ M
<P>If you open a Connection object with DefaultCursorDriver set to </P> 5 a$ i' ^) d& R0 c<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>1 m: l0 x; j3 q3 k4 }6 I% i
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>- O5 @- k+ s/ f0 N
<P>h in the lockedits argument to enable update caching. See the Update method </P> ! H) r0 |; j$ J( [7 I<P>topic for details about how to write changes to disk immediately, or to cache </P>+ C6 n, h" }7 I9 D0 P
<P>changes and write them to disk as a batch. </P>& P2 G- F9 R$ R4 g' f
<P> </P># l2 P( @, w/ H: ]" _0 m$ F g. P/ |( a( R
<P>Closing a Recordset with the Close method automatically deletes it from the </P> 3 |! a, x* W# i& x" u' K& z/ M4 `/ I$ e% q: j3 W- j
<P>Recordsets collection. </P> ( O$ E- f. b8 B6 D<P> </P> 8 ~0 Q, `3 u( ?8 c<P>Note If source refers to an SQL statement composed of a string concatenated </P> ( Y6 n7 o2 R! s& t: x# J9 }2 J' I8 O. |<P>with a non-integer value, and the system parameters specify a non-U.S. </P>- r1 `" L* b: H+ L& v8 X2 C
<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P>& c$ X# A* I8 A4 L8 s/ L3 S. u
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P>7 d% g6 A0 T a1 t' ]1 t
<P>Recordset. This is because during concatenation, the number will be converted </P>3 e _/ R( f9 o
<P>to a string using your system's default decimal character, and SQL only </P> ( S0 s/ N6 u5 h<P>accepts U.S. decimal characters.</P>