<> </P> ) n3 c. { t6 ^- _$ z* a<>Creates a new Recordset object and appends it to the Recordsets collection. </P>4 q& L7 m1 S- _8 U: r
<> </P> / V; i: ]8 Y0 Y( E6 D' I5 Z<>Syntax </P> ( t0 w+ x. e. {2 r# C<> </P> - g! G- w' b4 k& R<>For Connection and Database objects: </P> 7 N8 f' o" r) E5 Z& q! v# y$ e6 x<> </P>2 {. y* d8 l! o# x
<>Set recordset = object.OpenRecordset (source, type, options, lockedits) </P>4 t6 f' v$ l) W8 j
<> </P> * H# w3 }4 ?$ p9 H<>For QueryDef, Recordset, and TableDef objects: </P>3 U/ | D) S3 n. t$ ~4 R0 p
<> </P>/ g- h/ L: Z) C& i9 b3 t: e( ]6 p
<>Set recordset = object.OpenRecordset (type, options, lockedits) </P> 6 y7 x% w: p& y! B% X( s<> </P> 6 ~# V& s& }. Y& G+ U; r<>The OpenRecordset method syntax has these parts. </P> ! N# s7 }9 d" V# a6 ?$ @/ V/ |8 G<> </P> 0 l5 `2 ~" H: z" G ^<>art Description </P> $ f- j& p* i2 Z( {* ^4 {2 e f<>recordset An object variable that represents the Recordset object you wantt to </P> 3 \+ [3 Q- j" S6 j5 A! S5 w) c' w<>open. </P> ' A9 y4 Z9 `2 ]0 r/ N. m<>object An object variable that represents an existing object from which you </P>" N2 I! \6 C {2 b2 B* q
<>want to create the new Recordset. </P> : ~! e1 d- l6 X2 P<>source A String specifying the source of the records for the new Recordset. </P>8 [6 [. T4 h7 q3 q0 ?
<>The source can be a table name, a query name, or an SQL statement that </P> ' y0 ~5 g" Y& Y8 w" u6 O<>returns records. For table-type Recordset objects in Microsoft Jet databases, </P>+ h5 D4 d4 H& j$ J. e, S' i# F( `
<>the source can only be a table name. </P>1 b1 [2 F0 ~& b1 ]" q
<>type Optional. A constant that indicates the type of Recordset to open, as </P>) X& Q P: Z, Y) g
<>specified in Settings. </P> 9 s: h; |! F* x" w% T<>options Optional. A combination of constants that specify characteristics of </P> 2 R9 u! w7 |6 x6 R- N* V& P9 G<>the new Recordset, as listed in Settings. </P>1 v2 R2 w, ]1 H
<>lockedits Optional. A constant that determines the locking for the Recordsset, </P>/ J1 o/ {6 A( A
<P>as specified in Settings. </P> 5 H3 H1 [' u) x/ [( v; u<P>Settings </P> 7 N4 J; E6 W& I# y; }; P<P> </P> g9 X1 @1 z6 M0 e& F<P>You can use one of the following constants for the type argument. </P># u1 R; K. Q* T+ D- C( ?/ u+ R
<P> </P> 5 ~( Q5 r [9 J; L2 [8 v<P>Constant Description </P> 1 A0 n, Y2 W- u: U<P> </P> v% C! o" S7 |, }' J( g+ o) a+ X
<P> </P> ' Q1 V6 E' c3 p, ]$ f<P>dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces </P> 9 L; \1 ^+ B( @) U1 T8 e& d<P>only). </P> ! f0 n3 J5 N8 E. ~. c: [<P>dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an </P>" _5 x( q5 _+ S3 ^# w {1 C! o% M
<P>ODBC dynamic cursor. (ODBCDirect workspaces only) </P> 4 X7 n4 W6 d2 h<P>dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an </P> $ j$ U" Y6 U& T6 a( ~1 ]& C9 N% P<P>ODBC keyset cursor. </P>5 Y& C2 }; _9 O1 E
<P>dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an </P>% H' o# v% Z" P/ N1 _
<P>ODBC static cursor. </P>( i" G2 D* M( x, C( s3 H6 a
<P>dbOpenForwardOnly?Opens a forward-only-type Recordset object. </P>9 ^ M' Q1 p8 V5 I/ w
<P>Note If you open a Recordset in a Microsoft Jet workspace and you don't </P> , G9 F- y' ?9 k8 b$ n+ n<P>specify a type, OpenRecordset creates a table-type Recordset, if possible. If </P>- a' P. O2 [4 e
<P>you specify a linked table or query, OpenRecordset creates a dynaset-type </P>) y5 O0 M% J& T
<P>Recordset. In an ODBCDirect workspace, the default setting is dbOpenForwardOnl </P>( g* P# e6 t H' ?7 P4 ?6 r' w" ?
<P>y. </P> & F2 l* {+ P3 Y2 M9 u- a1 p# U! t# Q<P> </P>9 h! Z; Q' S0 G& x' p9 l
<P>You can use a combination of the following constants for the options </P>& O7 H( K( G* s& K4 [; y3 g! [
<P>argument. </P>2 @& O0 j- o. D( x" A2 E9 ?
<P> </P>: S' V) i8 y3 c$ L' P
<P>Constant Description </P> / q; L" q1 a6 p* f! ~% G<P>dbAppendOnly?Allows users to append new records to the Recordset, but </P> 9 z% o- D* X, P- K<P>prevents them from editing or deleting existing records (Microsoft Jet </P> & N5 o7 [8 a( z5 F<P>dynaset-type Recordset only). </P> + w9 B: L# o% O4 v1 l6 V<P>dbSQLPassThrough?Passes an SQL statement to a Microsoft Jet-connected ODBC </P> & c9 b7 {& T: g# R<P>data source for processing (Microsoft Jet snapshot-type Recordset only). </P> " a3 \) O" p5 m: J<P>dbSeeChanges Generates a run-time error if one user is changing data that </P> * j* U6 A' c( J<P>another user is editing (Microsoft Jet dynaset-type Recordset only). This is </P>( L7 F! d0 b5 ^' M
<P>useful in applications where multiple users have simultaneous read/write </P>0 ?# ]( Y$ u, d+ d( C& V
<P>access to the same data. </P> % M! s3 y- I+ s1 X+ u<P>dbDenyWrite?Prevents other users from modifying or adding records (Microsoft </P> + P% S2 i6 j! j) `# p3 x3 X<P>Jet Recordset objects only). </P> % p! V( D/ T: N+ z( s2 a<P>dbDenyRead?Prevents other users from reading data in a table (Microsoft Jet </P> # o9 L8 D# ?% b( ?; l, \<P>table-type Recordset only). </P>" j. e$ G! C) ?% e, E7 y0 [3 C# i
<P>dbForwardOnly?Creates a forward-only Recordset (Microsoft Jet snapshot-type </P>9 O- ^0 Y7 j8 u% v2 `7 n
<P>Recordset only). It is provided only for backward compatibility, and you </P> 0 c, J9 a. G* o9 R6 w<P>should use the dbOpenForwardOnly constant in the type argument instead of </P> 7 Z. s5 ?) S4 m( i Q<P>using this option. </P>9 M; t' c( S2 O2 f* S( n q( E
<P>dbReadOnly?Prevents users from making changes to the Recordset (Microsoft Jet </P> 0 ?3 x; |* a' [7 v<P>only). The dbReadOnly constant in the lockedits argument replaces this </P>0 y& B! d% E( x8 {
<P>option, which is provided only for backward compatibility. </P> 1 A6 ^/ W# D. h! C+ ^<P>dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only). </P> 7 k& d& Q; g. a9 t<P>dbExecDirect?Runs a query by skipping SQLPrepare and directly calling </P>4 M: J I W$ [; ?: _ p0 l" Q
<P>SQLExecDirect (ODBCDirect workspaces only). Use this option only when you抮e </P> 1 R( T$ b4 b$ I2 d4 z" e. e<P>not opening a Recordset based on a parameter query. For more information, see </P> G4 y/ d' |% D7 Y. s<P>the "Microsoft ODBC 3.0 Programmer抯 Reference." </P> % ^% R0 V& j5 X% e+ K. t. X<P>dbInconsistent?Allows inconsistent updates (Microsoft Jet dynaset-type and </P>% Z& F. p' H2 ?2 G6 Q
<P>snapshot-type Recordset objects only). </P>2 D9 X( V+ {. w! M- T
<P>dbConsistent?Allows only consistent updates (Microsoft Jet dynaset-type and </P>7 k% F$ t( y* i' v5 y; ~0 i! S
<P>snapshot-type Recordset objects only). </P> $ R' @! M8 e" u8 X<P>Note The constants dbConsistent and dbInconsistent are mutually exclusive, </P>& R. G4 {% T) f0 C' v- b
<P>and using both causes an error. Supplying a lockedits argument when options </P>" @1 j, k( s, k6 c: u
<P>uses the dbReadOnly constant also causes an error. </P> D* n6 H( V% S+ [4 I0 D<P> </P> 2 e8 d5 G3 Y$ H- l<P>You can use the following constants for the lockedits argument. </P> . }; Z5 p5 a# V+ L2 ^<P> </P> 9 J5 N) p; N* u/ i {& d: q0 N<P>Constant Description </P>2 u, K2 K8 j# V7 V+ C
<P>dbReadOnly Prevents users from making changes to the Recordset (default for </P> C+ l2 t3 U E5 \& _<P>ODBCDirect workspaces). You can use dbReadOnly in either the options argument </P>+ x0 _: F4 `1 r. s; M
<P>or the lockedits argument, but not both. If you use it for both arguments, a </P>% |" C# _/ T4 l6 b
<P>run-time error occurs. </P> 1 d7 m. R" Z1 ^<P>dbPessimistic?Uses pessimistic locking to determine how changes are made to </P>) U3 q/ j5 S9 R+ R: H7 j% ^
<P>the Recordset in a multiuser environment. The page containing the record </P>/ c- \- }% h7 _, ^
<P>you're editing is locked as soon as you use the Edit method (default for </P> 7 ?) z" u. f* k1 D9 H<P>Microsoft Jet workspaces). </P>( K1 M7 o$ t% v
<P>dbOptimistic?Uses optimistic locking to determine how changes are made to the </P> 5 _( ?! D P1 N; h$ I<P>Recordset in a multiuser environment. The page containing the record is not </P> 3 ~, z$ M8 X% ]6 U/ k. {% q3 F<P>locked until the Update method is executed. </P>" Z, Z% v4 H2 D- m
<P>dbOptimisticValue?Uses optimistic concurrency based on row values (ODBCDirect </P> % h( z$ A5 q. b, A- Q<P>workspaces only). </P> , j5 [3 }1 B& K, j5 A9 m) [<P>dbOptimisticBatch?Enables batch optimistic updating (ODBCDirect workspaces </P> % h3 h% n6 F8 P* Y% j6 A<P>only). </P> % N; Z# n5 K$ }9 o; {; Z<P>Remarks </P> 2 y9 F w; r8 a<P> </P> 6 D n% T. a; o% k8 b<P>In a Microsoft Jet workspace, if object refers to a QueryDef object, or a </P>) t, E% r2 L; r- ^ g; \
<P>dynaset- or snapshot-type Recordset, or if source refers to an SQL statement </P> 0 p4 B: T& b/ \( ^' E+ w<P>or a TableDef that represents a linked table, you can't use dbOpenTable for </P> / ^" `& o. Z+ @# v2 `<P>the type argument; if you do, a run-time error occurs. If you want to use an </P>$ f1 ~: k$ s6 ]( |- b
<P>SQL pass-through query on a linked table in a Microsoft Jet-connected ODBC </P>, ^, D$ `. P: K" A6 {
<P>data source, you must first set the Connect property of the linked table's </P>/ p$ e* l8 i8 d
<P>database to a valid ODBC connection string. If you only need to make a single </P> $ D2 q1 H$ B- B8 O! r# t! @3 |<P>pass through a Recordset opened from a Microsoft Jet-connected ODBC data </P>8 B! }/ i. S# Z6 |) z4 \3 {2 Z: ^
<P>source, you can improve performance by using dbOpenForwardOnly for the type </P>! {) o5 R8 l5 S# z
<P>argument. </P>+ j O# q ~& ^6 Q( ~
<P> </P> ! n9 M2 ?1 m0 W3 b6 @<P>If object refers to a dynaset- or snapshot-type Recordset, the new Recordset </P>! U% L o; i/ v4 D5 h: Q
<P>is of the same type object. If object </P> 9 i; u c* I7 l' f' v<P> refers to a table-type Recordset object, the type of the new object is a </P>( t+ t1 {3 U, V1 z
<P>dynaset-type Recordset. You can't open new Recordset objects from forward-only </P> : k j8 j9 }) p- `- v# Y<P>杢ype or ODBCDirect Recordset objects. </P>1 t( N4 M) y- I+ s
<P>In an ODBCDirect workspace, you can open a Recordset containing more than one </P>8 _$ j+ T4 o# @$ i7 n7 k
<P>select query in the source argument, such as </P>8 O0 F0 H: H6 I. m6 ^3 }; `0 i
<P> </P> ; A1 f+ `- V/ a<P>"SELECT LastName, FirstName FROM Authors </P>1 i; ^; F# A$ y7 V _" D
<P>WHERE LastName = 'Smith'; </P>0 Z E# Q; ~& k2 s
<P>SELECT Title, ISBN FROM Titles </P> 8 r2 X+ X# s; k- u' E, f. B6 x<P>WHERE ISBN Like '1-55615-*'" </P>% j0 ?! Q0 U N) w
<P> </P> * ~, D& Z1 G& {# O! q7 p: ` `0 g<P>The returned Recordset will open with the results of the first query. To </P> - c: P# [1 c" y0 [0 z3 ]* N9 S<P>obtain the result sets of records from subsequent queries, use the </P> 6 G3 r/ _6 ?9 s, L9 _9 t<P>NextRecordset method. </P># T8 D# E" A' H5 b- A
<P> </P> 4 G7 `# c9 \! M2 h0 C% j* O<P>Note You can send DAO queries to a variety of different database servers </P> 4 e4 Y6 `1 c5 e9 O. @% t<P>with ODBCDirect, and different servers will recognize slightly different </P>6 X4 ^, I) f5 b4 c. Q
<P>dialects of SQL. Therefore, context-sensitive Help is no longer provided for </P>4 W/ g1 S R: t" Y8 V& c T! Q( r
<P>Microsoft Jet SQL, although online Help for Microsoft Jet SQL is still </P> " X' q& a( }8 @3 r- @/ C9 r<P>included through the Help menu. Be sure to check the appropriate reference </P> * `* b% @' B& }<P>documentation for the SQL dialect of your database server when using either </P>; j5 M$ |4 @) p2 A" {
<P>ODBCDirect connections or pass-through queries in Microsoft Jet-connected </P> ( _$ L$ _+ d- ~$ w' X+ A<P>client/server applications. </P> ! D8 }- ^+ x/ }) l7 v% [' S<P> </P>; R8 D2 l- s! O0 F& c4 f2 ]
<P>Use the dbSeeChanges constant in a Microsoft Jet workspace if you want to </P>6 r4 H$ l! k3 D* I0 Q: ^
<P>trap changes while two or more users are editing or deleting the same record. </P> , n3 b' z$ Z% D$ s- `<P>For example, if two users start editing the same record, the first user to </P>9 ]( K4 t9 O4 R
<P>execute the Update method succeeds. When the second user invokes the Update </P> . o- N6 t2 U/ v3 T3 d' x& D<P>method, a run-time error occurs. Similarly, if the second user tries to use </P> / h2 V" o3 x2 \. Q+ e6 |* j0 x<P>the Delete method to delete the record, and the first user has already </P> ' O$ X- A8 }: v! h<P>changed it, a run-time error occurs. </P>$ I& d* }4 Z+ B; [* B
<P> </P> i* P% s( m; o( H6 g" c
<P>Typically, if the user gets this error while updating a record, your code </P>0 l$ e5 K5 p# I2 m9 |# d* Z3 s
<P>should refresh the contents of the fields and retrieve the newly modified </P> ( I# {+ ]1 Y& X {<P>values. If the error occurs while deleting a record, your code could display </P> " P. `3 S7 ]. v( Z1 t. j<P>the new record data to the user and a message indicating that the data has </P> 8 N5 P+ f' g- w$ Z* }5 L8 c, h<P>recently changed. At this point, your code can request a confirmation that </P> 8 j0 d3 @+ l* V( ]9 n) I) p8 |<P>the user still wants to delete the record. </P>/ P0 Y/ u f, r( S/ f3 t
<P> </P>6 h* S& \6 [$ W$ B
<P>You should also use the dbSeeChanges constant if you open a Recordset in a </P> - ~8 V1 e! l' Z<P>Microsoft Jet-connected ODBC workspace against a Microsoft SQL Server 6.0 (or </P> X' e+ ~* @# h. b<P>later) table that has an IDENTITY column, otherwise an error may result. </P>6 G. B. B( Y1 s" V) g% k2 H
<P> </P>; ?/ y4 J( x5 X" `& ?
<P>In an ODBCDirect workspace, you can execute asynchronous queries by setting </P>3 M2 ]- s' }$ p& |: F0 ~7 }% A
<P>the dbRunAsync constant in the options argument. This allows your application </P> 6 r" b* r0 o4 t, x<P>to continue processing other statements while the query runs in the </P> " a9 m) w9 ?+ W, B) @1 B<P>background. But, you cannot access the Recordset data until the query has </P>$ D' m! L; C. Z7 V- O- s
<P>completed. To determine whether the query has finished executing, check the </P>1 h- }* h( b/ V5 T. ?
<P>StillExecuting property of the new Recordset. If the query takes longer to </P> $ ?* }0 e9 f; j& @2 S. i! t<P>complete than you anticipated, you can terminate execution of the query with </P>* C& Y4 t2 _7 s+ c
<P>the Cancel method. </P> ; x/ u7 b- W u" q8 n<P> </P> $ k6 R( ^, u8 @, M- g<P>Opening more than one Recordset on an ODBC data source may fail because the </P> 2 S1 V6 t B) t& x<P>connection is busy with a prior </P> ( z. X+ @0 L3 ]4 i0 S1 _<P>OpenRecordset call. One way around this is to use a server-side cursor and </P>) C2 B, G9 t5 }3 v/ @
<P>ODBCDirect, if the server supports this. Another solution is to fully </P> 4 W# U2 V& ]! O# d% d' _<P>populate the Recordset by using the MoveLast method as soon as the Recordset </P>2 S4 o7 s9 n5 E
<P>is opened. </P> ; w( [" a5 A' b' @: R6 Z' d<P> </P> & ]4 N# m& z0 v7 W6 c# b0 }5 k4 a<P>If you open a Connection object with DefaultCursorDriver set to </P># `; |5 k2 M0 E; {, e4 ?
<P>dbUseClientBatchCursor, you can open a Recordset to cache changes to the data </P>8 R& B3 u% X* J# m# E
<P>(known as batch updating) in an ODBCDirect workspace. Include dbOptimisticBatc </P>$ ~; |# t- v0 t2 L
<P>h in the lockedits argument to enable update caching. See the Update method </P>. J# {2 m: o5 [0 l. N, D- a7 ?
<P>topic for details about how to write changes to disk immediately, or to cache </P> % {2 M4 D% U1 p, {$ Z<P>changes and write them to disk as a batch. </P> 7 \0 `4 t: o, o<P> </P>4 y) B5 E# q3 Z+ f0 D
<P>Closing a Recordset with the Close method automatically deletes it from the </P> - K# h/ h3 `9 ~( F; b2 L, b( y; F4 @7 `2 L& S1 W* V' Y1 V
<P>Recordsets collection. </P># f1 D7 Q5 `1 m; {8 t. m& `
<P> </P> - z' Z7 d/ c! }$ ?, R<P>Note If source refers to an SQL statement composed of a string concatenated </P> : F3 [1 P' {8 I5 w: U1 J/ \/ t<P>with a non-integer value, and the system parameters specify a non-U.S. </P> 8 E5 [. a! D7 n' {7 c: D' B) a' J<P>decimal character such as a comma (for example, strSQL = "PRICE > " & </P>7 b" t- V$ K) s: E, H# n# S( X
<P>lngPrice, and lngPrice = 125,50), an error occurs when you try to open the </P> & p& {' I- o: ?- Y/ r7 w<P>Recordset. This is because during concatenation, the number will be converted </P> ! ], ?+ k I6 X. |/ L1 h<P>to a string using your system's default decimal character, and SQL only </P> 9 t! u- b7 Q9 _8 x1 I<P>accepts U.S. decimal characters.</P>