Newsgroup: it.comp.lang.visual-basic
Titolo: ADO - Problemi ad Aggionare i Record

Ciao Amici,
qualche giorno fa, vi ho scritto per trovare aiuti per tramutare il mio
codice da Dao (e Db di Access 2000) ad ADO (e DB di M$ SQL server 2000),+
o - ci sono, ma ho riscontrato qualche problemino, molto noioso, ad esempio,
prima utilizzavo la Sub Data1.Reposition () per filtrare i record di una
tabella correlata (Fatture o----ooFatt_Dati), e il codice è questo:
Private Sub Data1_Reposition()
On Error Resume Next
Data1.Caption = "Fattura: " & (Data1.Recordset.AbsolutePosition + 1) & " di
" & Data1.Recordset.RecordCount
With Data2
.RecordSource = "select * from FATT_DATI where DT_NUM_FATTURA ='" & (Text10)
& "'"    'VOCI FATTURA
.Refresh
.Recordset.MoveLast
End With
If err then Gest_Err
End Sub
ora in ADO non esiste più Reposition, ma MoveComplete, e fino a qui, ci
sono, il fatto è che col MoveComplete non mi filtra in sontonia, cioè,
esempio, la fattura è la N° 5, mi sposto indietro o in avanti e  mi ritrovo
le voci fattura del record precedente...
ho dovuto filtrare le voci fattura, con la sub change della label assegnata
al Numero fattura...
Poi ho altri piccoli Problemi, ma spiegarli a porole non è semplice...
Suggeriementi?
grazie mille e buon lavoro.


wrote:

Ho fatto questo piccolo esempio per provare gli eventi di ado.
Eventualmente usandolo puoi capire dove intervenire.
Per funzionare ha solo bisogno di un db access con una tabella
"Tabprova" con 2 campi "codice" (intero), "Descr" (stringa)
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   2988
   ClientLeft      =   48
   ClientTop       =   432
   ClientWidth     =   6012
   LinkTopic       =   "Form1"
   ScaleHeight     =   2988
   ScaleWidth      =   6012
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdExecute 
      Caption         =   "Execute"
      Height          =   372
      Left            =   3960
      TabIndex        =   9
      Top             =   2400
      Width           =   852
   End
   Begin VB.TextBox txtMsg 
      Height          =   288
      Left            =   1320
      TabIndex        =   8
      Top             =   1320
      Width           =   4452
   End
   Begin VB.CommandButton cmdLast 
      Caption         =   "Last"
      Height          =   372
      Left            =   2880
      TabIndex        =   7
      Top             =   2400
      Width           =   732
   End
   Begin VB.CommandButton cmdNext 
      Caption         =   "Succ"
      Height          =   372
      Left            =   2040
      TabIndex        =   6
      Top             =   2400
      Width           =   732
   End
   Begin VB.CommandButton cmdPrev 
      Caption         =   "Prec"
      Height          =   372
      Left            =   1080
      TabIndex        =   5
      Top             =   2400
      Width           =   852
   End
   Begin VB.CommandButton cmdInizio 
      Caption         =   "Inizio"
      Height          =   372
      Left            =   120
      TabIndex        =   4
      Top             =   2400
      Width           =   852
   End
   Begin VB.TextBox txtDescr 
      Height          =   288
      Left            =   2760
      TabIndex        =   2
      Top             =   240
      Width           =   3012
   End
   Begin VB.TextBox txtCodice 
      Height          =   288
      Left            =   1320
      TabIndex        =   1
      Top             =   240
      Width           =   1332
   End
   Begin VB.Label Label2 
      Caption         =   "Messaggio:"
      Height          =   252
      Left            =   120
      TabIndex        =   3
      Top             =   1320
      Width           =   972
   End
   Begin VB.Label Label1 
      Caption         =   "Codice:"
      Height          =   252
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   972
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents rs As ADODB.Recordset
Attribute rs.VB_VarHelpID = -1
Private WithEvents cnn As ADODB.Connection
Attribute cnn.VB_VarHelpID = -1
Enum Naviga
    Frec = 0
    Prec = 1
    Nrec = 2
    Lrec = 3
End Enum
Private Sub cmdExecute_Click()
    cnn.Execute "Delete * from tabprova where tabprova.codice = 0"
End Sub
Private Sub cmdInizio_Click()
    NavigaRecord Naviga.Frec
End Sub
Private Sub cmdLast_Click()
    NavigaRecord Naviga.Lrec
End Sub
Private Sub cmdNext_Click()
    NavigaRecord Naviga.Nrec
End Sub
Private Sub cmdPrev_Click()
    NavigaRecord Naviga.Prec
End Sub
Private Sub Form_Load()
    Set rs = New ADODB.Recordset
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & App.Path & "\dati.mdb;Persist Security Info=False"
    cnn.Open
    rs.Open "tabprova", cnn, adOpenStatic, adLockOptimistic
    NavigaRecord Naviga.Frec
End Sub
Private Sub Form_Unload(Cancel As Integer)
    rs.Close
    Set rs = Nothing
    cnn.Close
    Set cnn = Nothing
End Sub
Private Sub rs_WillMove(ByVal adReason As ADODB.EventReasonEnum, _
                                adStatus As ADODB.EventStatusEnum, _
                                ByVal pRecordset As ADODB.Recordset)
    'PrintStatus "WillMove"
    PrintReason adReason
End Sub
Private Sub rs_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, _
                                ByVal pError As ADODB.Error, _
                                    adStatus As ADODB.EventStatusEnum,
_
                                ByVal pRecordset As ADODB.Recordset)
    'PrintStatus "MoveComplete"
    PrintReason adReason
End Sub
Sub PrintStatus(msg As String)
    txtMsg = msg
End Sub
Sub NavigaRecord(record As Naviga)
    If record = Naviga.Frec Then
        If Not rs.EOF Or Not rs.BOF Then rs.MoveFirst
    End If
    If record = Naviga.Nrec Then
        If rs.EOF = False Then rs.MoveNext
        If rs.EOF = True And rs.BOF = False Then rs.MoveLast
    End If
    If record = Naviga.Prec Then
        If rs.BOF = False Then rs.MovePrevious
        If rs.BOF = True And rs.EOF = False Then rs.MoveFirst
    End If
    If record = Naviga.Lrec Then
        If Not rs.EOF Or Not rs.BOF Then rs.MoveLast
    End If
    If Not rs.EOF And Not rs.BOF Then
        txtCodice = rs.Fields("codice")
        txtDescr = rs.Fields("descr")
    End If
End Sub
Private Sub cnn_WillExecute(Source As String, _
                CursorType As ADODB.CursorTypeEnum, _
                LockType As ADODB.LockTypeEnum, _
                Options As Long, _
                adStatus As ADODB.EventStatusEnum, _
                ByVal pCommand As ADODB.Command, _
                ByVal pRecordset As ADODB.Recordset, _
                ByVal pConnection As ADODB.Connection)
    PrintStatus "WillExecute"
    MsgBox "will Execute"
End Sub
Private Sub cnn_ExecuteComplete(ByVal RecordsAffected As Long, _
                                ByVal pError As ADODB.Error, _
                        adStatus As ADODB.EventStatusEnum, _
                        ByVal pCommand As ADODB.Command, _
                        ByVal pRecordset As ADODB.Recordset, _
                        ByVal pConnection As ADODB.Connection)
    PrintStatus "ExecuteComplete"
End Sub
Private Sub cnn_WillConnect(ConnectionString As String, _
                            UserID As String, _
                            Password As String, _
                            Options As Long, _
                            adStatus As ADODB.EventStatusEnum, _
                            ByVal pConnection As ADODB.Connection)
    PrintStatus "WillConnect"
    MsgBox "willconnect"
End Sub
Private Sub PrintReason(adReason As ADODB.EventReasonEnum)
    Select Case (adReason)
        Case adRsnAddNew:
            PrintStatus "AddNew"
        Case adRsnClose:
            PrintStatus "Close"
        Case adDelete:
            PrintStatus "Delete"
        Case adRsnFirstChange:
            PrintStatus "First Change"
        Case adRsnMove:
            PrintStatus "Move"
        Case adRsnMoveFirst:
            PrintStatus "MoveFirst"
        Case adRsnMoveLast:
            PrintStatus "MoveLast"
        Case adRsnMoveNext:
            PrintStatus "MoveNext"
        Case adRsnMovePrevious:
            PrintStatus "MovePrevious"
        Case adRsnRequery:
            PrintStatus "Requery"
        Case adRsnResynch:
            PrintStatus "Resynch"
        Case adRsnUndoAddNew:
            PrintStatus "Undo AddNew"
        Case adRsnUndoDelete:
            PrintStatus "Undo Delete"
        Case adRsnUndoUpdate:
            PrintStatus "Undo Update"
        Case adRsnUpdate:
            PrintStatus "Update"
        End Select
End Sub
=======================================================================
Se mi vuoi scrivere togli le maiuscole
Sveltolampo 
cteniza...@hotmail.com
=======================================================================

     Set cnn = Nothing
sovversivo :P