0

I opened an old project of Access. I have some problems with these objects that are no longer used.
I'm following this guide: http://support.microsoft.com/kb/129883/en

The part of the code in question is this:

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....

Following the guide, I changed to:

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)

It gives me error here: Dyna.[Codice Articolo]

[Codice Articolo] is a field in the table TOrdiniCartone

Does anyone know these things?

4

1 回答 1

1

Dyna 应该被定义为一个 dao.recordset:

Dim Dyna As DAO.Recordset

可以引用字段

Dyna.Fields("Field Name")

或者

Dyna.Fields(<index>) 

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

你也可以做

Dyna![FieldName]
于 2013-03-05T18:50:11.657 回答