Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > MS Access > переписать номера записей


Автор: Aleksandra 24.4.2008, 12:35
Здравствуйте.

Для того, чтобы переписать номера записей в разделе я сделала такой код и он работает:

Код

c = DCount("NPP", "tblBook", "IDRazd =" & Forms![frmVer]![SubFormVer].[Form]![IDRazd])
       For i = 1 To c
              Me.NPP = i
         Me.Recordset.MoveNext
       Next i


Как записать тот же код через рекордсет, а не через объекты экрана?

Спасибо...

Автор: Akina 24.4.2008, 14:28
А точно так же...

Код

set rs = openrecordset ("...")
n=1
with rs
  .movefirst
  do while not .eof 
    !NPP = n
    n=n+1
  loop
.close
end with
set rs = nothing

Автор: Aleksandra 24.4.2008, 23:21
Что-то не работает...

Как правильно записать выражение в скобках:
set rs = openrecordset ("...")

??

Автор: Fortop 24.4.2008, 23:46
Если я правильно помню, то это SQL запрос должен быть.

Добавлено @ 23:49
неправильно помню smile

MSDN для ADO
Код

recordset.Open Source, ActiveConnection, CursorType, LockType, Options
 
Parameters
Source 
Optional. A Variant that evaluates to a valid Command object, an SQL statement, a table name, a stored procedure call, a URL, or the name of a file or Stream object containing a persistently stored Recordset. 
ActiveConnection 
Optional. Either a Variant that evaluates to a valid Connection object variable name, or a String that contains ConnectionString parameters. 
CursorType 
Optional. A CursorTypeEnum value that determines the type of cursor that the provider should use when opening the Recordset. The default value is adOpenForwardOnly. 
LockType 
Optional. A LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the Recordset. The default value is adLockReadOnly. 
Options 
Optional. A Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object, or that the Recordset should be restored from a file where it was previously saved. Can be one or more CommandTypeEnum or ExecuteOptionEnum values, which can be combined with a bitwise AND operator. 


MSDN для DAO
Код

   Dim dbsNorthwind As Database
   Dim rstTable As Recordset
   Dim rstDynaset As Recordset
   Dim rstSnapshot As Recordset
   Dim rstForwardOnly As Recordset
   Dim rstLoop As Recordset
   Dim prpLoop As Property

   Set dbsNorthwind = OpenDatabase("Northwind.mdb")

   With dbsNorthwind

      ' Open one of each type of Recordset object.
      Set rstTable = .OpenRecordset("Categories", _
         dbOpenTable)
      Set rstDynaset = .OpenRecordset("Employees", _
         dbOpenDynaset)
      Set rstSnapshot = .OpenRecordset("Shippers", _
         dbOpenSnapshot)
      Set rstForwardOnly = .OpenRecordset _ 
         ("Employees", dbOpenForwardOnly)



Добавлено @ 23:54
ну и то, о чем говорил я.
Цитата


Syntax

expression.OpenRecordset(Name, Type, Options, LockEdit)

expression   A variable that represents a Database object.

Parameters

Name Required String The source of the records for the new Recordset. The source can be a table name, a query name, or an SQL statement (SQL string/statement: An expression that defines an SQL command, such as SELECT, UPDATE, or DELETE, and includes clauses such as WHERE and ORDER BY. SQL strings/statements are typically used in queries and in aggregate functions.) that returns records. For table-type Recordset objects in Microsoft Access database engine databases, the source can only be a table name. 
Type Optional Variant A RecordsetTypeEnum constant that indicates the type of Recordset to open.
  Note 
If you open a Recordset in a Microsoft Access workspace (Access workspace: A workspace that uses the Access database engine to access a data source. The data source can be an Access database file, an ODBC database, such as a Paradox database, or an ISAM database.) and you don't specify a type, OpenRecordset creates a table-type Recordset, if possible. If you specify a linked table (linked table: A table stored in a file outside the open database from which Access can access records. You can add, delete, and edit records in a linked table, but you cannot change its structure.) or query, OpenRecordset creates a dynaset-type Recordset.
 
 
Options Optional Variant A combination of RecordsetOptionEnum constants that specify characteristics of the new Recordset.
  Note 
The constants dbConsistent and dbInconsistent are mutually exclusive, and using both causes an error. Supplying a lockedits argument when options uses the dbReadOnly constant also causes an error. 

 
LockEdit Optional Variant A LockTypeEnum constant that determines the locking for the Recordset.
  Note 
You can use dbReadOnly in either the options argument or the lockedits argument, but not both. If you use it for both arguments, a run-time error occurs. 


Автор: Aleksandra 25.4.2008, 00:36
Ну я и писала так:

Код

strSQL = "Select NPP, IDRazd FROM tblBook where IDRazd = " & Me.IDRazd & ""

Set rs = CurrentDb.OpenRecordset(strSQL)
n = 1
With rs
  .MoveFirst
  Do While Not .EOF
    !NPP = n
    n = n + 1
  Loop
.Close
End With
Set rs = Nothing

Возникает ошибка в  !NPP = n

Автор: Fortop 25.4.2008, 01:50
Цитата(Aleksandra @  25.4.2008,  00:36 Найти цитируемый пост)
Возникает ошибка в  !NPP = n 

Я уже смутно помню синтаксис VB
Что именно за ошибка? Что пишется?

Автор: Aleksandra 25.4.2008, 02:06
Run-time error 3020:
Update or CancelUpdate without AddNew or Edit

После нажимаю на кнопку Debug и вижу выделение строки с !NPP = n

Автор: Akina 25.4.2008, 08:22
Цитата(Aleksandra @  25.4.2008,  01:36 Найти цитируемый пост)
Возникает ошибка в  !NPP = n 

Перед этой строкой должно быть .Edit, а после соответственно .Update

M
Akina
Aleksandra, когда используете тег "Код", смотрите, какой именно диалект вы выбираете. Использовать подсветку SQL для кода на VBA - неправильно...


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)