访问动态集和快照

时间:2013-03-05 16:40:08

标签: ms-access snapshot

我开了一个旧的Access项目。我对这些不再使用的物体有些问题 我正在关注本指南:http://support.microsoft.com/kb/129883/en

有问题的代码部分是:

Private Sub AGG_Dati()

Dim Dyna As Dynaset
Dim DB As Database

Set DB = CurrentDb()
Set Dyna = DB.CreateDynaset("SELECT DISTINCTROW TOrdiniCartone.* FROM TOrdiniCartone WHERE ((TOrdiniCartone.[Tipo Ordine] = ""S""));")

If Dyna.RecordCount > 0 Then Dyna.MoveLast
n = Dyna.RecordCount
If n > 0 Then
    Dyna.MoveFirst
    If " " & Forms![SOrdiniArticoli].[_CArt] <> " " & Dyna.[Codice Articolo] Then
       Forms![SOrdiniArticoli].[_CArt] = Dyna.[Codice Articolo]
       Forms![SOrdiniArticoli].[_CForn] = ""
       MsgBox "Selezionare un Fornitore!"
       Stato = 1
    Else....

按照指南,我改为:

Private Sub AGG_Dati()

Dim Dyna As Recordset
Dim DB As Database

Set DB = CurrentDb()
Set Dyna = DB.OpenRecordset("SELECT DISTINCTROW TOrdiniCartone.* FROM TOrdiniCartone WHERE ((TOrdiniCartone.[Tipo Ordine] = ""S""));", dbOpenDynaset)

这给了我错误:Dyna。[Codice Articolo]

[Codice Articolo]是TOrdiniCartone表中的一个字段

有谁知道这些事情?

1 个答案:

答案 0 :(得分:1)

Dyna应定义为dao.recordset:

Dim Dyna As DAO.Recordset

可以引用字段

Dyna.Fields("Field Name")

Dyna.Fields(<index>) 

其中索引从第一列的0开始。

您也可以

Dyna![FieldName]