Una famiglia di sistemi di gestione per database relazionali di Microsoft progettati per semplificare l'uso.
Ciao Luca,
purtroppo nella "sottomaschera_CRONOPROGRAMMA" ci sono un po' di errori.
Non so se già te l'avevo consigliato, la cosa più importante da fare è inserire la dichiarazione obbligatoria delle variabili "Option Explicit".
Se l'avessi fatto, tale dichiarazione ti avrebbe condotto ad errori che ho in qualche modo corretto e che puoi verificare.
Seleziona e copia tutto il codice qui sotto, apri la sottomaschera in visualizzazione struttura, entra in uno dei moduli e dopo dopo aver selezionato tutto il codice, incolli.
Option Compare Database
Option Explicit ' <- da aggiungere
Dim nAnni As Integer
Dim nn As Integer
Private Sub ANNO_CRONO_BeforeUpdate(Cancel As Integer)
If ANNO_CRONO < Year(Now()) Then
MsgBox "ATTENTIONE !!! L'annualià inserita è antecedente a quella attuale.", vbInformation
' scritto male -> cencel = True
Cancel = True
Me.Undo
End If
End Sub
Private Sub ANNO_CRONO_GotFocus()
nn = Me!ANNO_CRONO
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim n As Variant
If Parent!COLLAUDATO = False Then
If DCount("RESIDUO_CRONO", "QRY_RESIDUO_CRONO_PROGETTO", "ID_PROG=" & Me!ID_PROG) > 0 Then
n = DLookup("RESIDUO_CRONO", "QRY_RESIDUO_CRONO_PROGETTO", "ID_PROG=" & Me!ID_PROG) - Me!IMPORTO_CRONO
Else
n = Parent!IMPORTO_PROGETTO - Me!IMPORTO_CRONO
End If
If Me!IMPORTO_CRONO = 0 Then
MsgBox "Attenzione, i dati sono incompleti" & vbCrLf & _
"Per annullare i dati premere - esc - sulla tastiera.", vbInformation
Me!IMPORTO_CRONO.SetFocus
Cancel = True
Exit Sub
End If
If Nz(DSum("IMPORTO_CRONO", "CRONO", "ID_PROG=" & Me!ID_PROG)) + _
Me!IMPORTO_CRONO > Parent!IMPORTO_PROGETTO Then
MsgBox "Il cronoprogramma complessivo è maggiore dell'importo del progetto." & vbCrLf & "I dati inseriti verranno annullati.", vbInformation
Cancel = True
Me.Undo
Exit Sub
End If
If Nz(DSum("IMPORTO_CRONO", "CRONO", "ID_PROG=" & Me!ID_PROG)) + _
Me!IMPORTO_CRONO < Parent!IMPORTO_PROGETTO Then
MsgBox "L'importo residuo ancora da programmare per il progetto corrente è di " & Format$(n, "€ " & "#,###.00"), vbInformation
ElseIf Nz(DSum("IMPORTO_CRONO", "CRONO", "ID_PROG=" & Me!ID_PROG)) + _
Me!IMPORTO_CRONO = Parent!IMPORTO_PROGETTO Then
MsgBox "Il cronoprogramma è stato correttamente compilato! ", vbInformation
End If
End If
Me!VERIFICA_CRONO = 1
End Sub
Private Sub ANNO_CRONO_AfterUpdate()
If DLookup("TOT_PROG_CRONO", "QRY_RESIDUO_CRONO_PROGETTO", "ID_PROG=" & Me!ID_PROG) = Parent!IMPORTO_PROGETTO And Parent!COLLAUDATO = 0 Then
MsgBox "Il cronoprogramma per il progetto corrente è stato compilato correttamente! ", vbInformation
'Dopo aggiornamento è errato -> Cancel = True
'Dopo aggiornamento è errato -> Me.Undo
Exit Sub
End If
Dim rs As DAO.Recordset
Dim i As Integer
If Me!IMPORTO_CRONO = 0 Then
Exit Sub
End If
Set rs = CurrentDb.OpenRecordset("Crono")
nAnni = Me!ANNO_CRONO - nn
For i = 1 To nAnni
rs.AddNew
rs!ID_PROG = Me.ID_PROG
rs!ANNO_CRONO = nn
rs!IMPORTO_CRONO = 1
rs!VERIFICA_CRONO = 1
rs.Update
nn = nn + 1
Next i
Me.Requery
End Sub
Private Sub IMPORTO_CRONO_BeforeUpdate(Cancel As Integer)
If Me!IMPORTO_CRONO > Parent!IMPORTO_PROGETTO And Parent!COLLAUDATO = 0 Then
MsgBox "Attenzione, l'importo inserito è maggiore dell'importo di progetto.", vbInformation
Me.Undo
Exit Sub
End If
End Sub
Private Sub IMPORTO_CRONO_Change()
If Me!VERIFICA_CRONO = 1 Then
If MsgBox("Attenzione, per modificare il record bisogna prima eliminarlo, continuare?", _
vbQuestion + vbCritical + vbYesNo) = vbNo Then
Me.Undo
Exit Sub
Else
Me.Undo
' DoCmd.OpenForm "ELIMINA_CRONOPROGRAMMA", , , "[ID_ PROG] = " & Me!ID_ PROG
Exit Sub
End If
End If
End Sub
Una volta fatto, potrai capire come implementare i record con il numero di date scelte e quale altro codice eliminare per evitare che ostacoli tale operazione.
Vladimiro