Ci provo, spero di non fare dei pocci. Ho aperto vb6 e il codice alunni, sono andato dove mi visualizza la maschera dove secondo me avviene l'errore, o scelto "visualizza codice" e ho copiato... Spero di non aver fatto degli errori (tipo aver copiato troppo). Se mi dite... sono disposto a allegare tutto il programma...
Grazie.


Option Explicit

Const titolo = "Voti"
Const Inizio = 2

Public Indice As Integer
Public lstItem As ListItem

Dim Caricamento As Boolean
Dim NumTesti As Integer

Private Sub cmbT_Click()
Dim tb As Recordset
Dim i As Integer

Set tb = DBGEN.OpenRecordset("SELECT * FROM materie WHERE classe = '" & cmbT & "'", dbOpenForwardOnly)

If tb.RecordCount = 0 Then
lblType(2) = "Materia:"
Altezza Inizio
Exit Sub
End If

For i = 4 To NumMaterie * 3
txtF(i).Visible = True
Next i
For i = 3 To NumMaterie + 1
lblType(i).Visible = True
Next i

For i = 1 To NumMaterie
If IsNull(tb("materia" & i)) Then Exit For
lblType(i + 1) = tb("materia" & i) & ":"
Next i

NumTesti = i
If optT(1) Then NascondiTestiSecondo True
Altezza i

End Sub

Private Sub cmdType_Click(Index As Integer)
Dim i As Integer
Dim tb As Recordset

If Index = 0 Then

If cmbT = "" Then
MsgBox "Inserire la classe.", vbInformation, titolo
Exit Sub
End If

If txtF(0) = "" Then
MsgBox "Inserire l'anno.", vbInformation, titolo
Exit Sub
End If

If txtF(0).Enabled Then
Set tb = DBGEN.OpenRecordset("SELECT codice FROM alunni WHERE codice = " & _
frmPrincipale.Keys & " AND anno = '" & txtF(0) & _
"' AND quad = " & IIf(optT(0), 1, 2), dbOpenForwardOnly)
If tb.RecordCount <> 0 Then
MsgBox "Una registrazione per quest'alunno con lo stesso anno e lo stesso " & _
"quadrimestre è già presente.", vbInformation, titolo
Exit Sub
End If
End If

Screen.MousePointer = vbHourglass

DBGEN.Execute "DELETE * FROM alunni WHERE codice = " & frmPrincipale.Keys & _
" AND anno = '" & txtF(0) & "' AND quad = " & IIf(optT(0), 1, 2)

Set tb = DBGEN.OpenRecordset("SELECT * FROM alunni WHERE codice = NULL", dbOpenDynaset)

tb.AddNew
tb!codice = frmPrincipale.Keys
tb("anno") = txtF(0)
tb("classe") = cmbT
tb!quad = IIf(optT(0), 1, 2)
For i = 1 To NumMaterie
If lblType(i + 1).Visible = False Then Exit For
tb("4materia" & i) = Left$(lblType(i + 1), Len(lblType(i + 1)) - 1)
If lblType(i + 1) <> "Condotta:" Then
If txtF((i - 1) * 3 + 1) <> "" Then tb("1materia" & i) = txtF((i - 1) * 3 + 1)
If txtF((i - 1) * 3 + 2) <> "" Then tb("2materia" & i) = txtF((i - 1) * 3 + 2)
If txtF(i * 3) <> "" Then tb("3materia" & i) = txtF(i * 3)
Else
If txtF((i - 1) * 3 + 1) <> "" Then tb("2materia" & i) = txtF((i - 1) * 3 + 1)
If txtF((i - 1) * 3 + 2) <> "" Then tb("2materia" & i) = txtF((i - 1) * 3 + 2)
If txtF(i * 3) <> "" Then tb("2materia" & i) = txtF(i * 3)
End If
Next i
If txtF(46) <> "" Then tb!risultato = txtF(46)
If txtF(47) <> "" Then tb!debito_prec = txtF(47)
If txtF(48) <> "" Then tb!debito = txtF(48)
If txtF(49) <> "" Then tb!credito = txtF(49)
tb.Update

Set tb = DBGEN.OpenRecordset("SELECT * FROM parametri_voti", dbOpenDynaset)
If tb.RecordCount <> 0 Then
tb.Edit
Else
tb.AddNew
End If
tb("anno") = IIf(txtF(0) <> "", txtF(0), Null)
tb("classe") = IIf(cmbT <> "", cmbT, Null)
tb!quad = IIf(optT(0), 1, 2)
tb.Update

Screen.MousePointer = vbDefault

End If

Unload Me

End Sub

Private Sub Form_Load()
Dim i As Integer, j As Integer
Dim itmX As ListItem
Dim tb As Recordset
Dim Valore1 As String, Valore2 As String, Valore3 As String, Valore4 As String
Dim Spazio1 As Integer, Spazio2 As Integer

Caricamento = True

lblType(0) = frmPrincipale.txtF(0) & " " & frmPrincipale.txtF(1)

For i = 1 To NumMaterie * 3
txtF(i).MaxLength = 10
Next i
For i = 46 To 49
txtF(i).MaxLength = 50
Next i

If Indice = -1 Then

Set tb = DBGEN.OpenRecordset("SELECT classe FROM materie ORDER BY classe", dbOpenForwardOnly)
cmbT.Clear
While Not tb.EOF
cmbT.AddItem tb("classe")
tb.MoveNext
Wend

For i = 4 To NumMaterie * 3
txtF(i).Visible = False
Next i
For i = 3 To NumMaterie + 1
lblType(i).Visible = False
Next i

NumTesti = 1

Set tb = DBGEN.OpenRecordset("SELECT * FROM parametri_voti", dbOpenForwardOnly)
If tb.RecordCount <> 0 Then
If Not IsNull(tb!quad) Then
optT(0) = IIf(tb!quad = 1, True, False)
Else
optT(0) = Format(Date, "mm") < 6
End If
If Not IsNull(tb("anno")) Then txtF(0) = tb("anno")
If Not IsNull(tb("classe")) Then
cmbT = tb("classe")
cmbT_Click
Else
Altezza Inizio
End If
Else
optT(0) = Format(Date, "mm") < 6
Altezza Inizio
End If
If txtF(0) = "" Then txtF(0) = Format(Date, "yyyy") - _
IIf(CInt(Format(Date, "mm")) > 8, 0, 1)
lblType(27) = "/" & txtF(0) + 1

Else

cmbT = Mid$(frmPrincipale.lblField(Indice), 9)
cmbT.Enabled = False
txtF(0) = Mid$(frmPrincipale.lblField(Indice + 1), 18, 4)
txtF(0).Enabled = False
optT(0).Value = Left$(lstItem, 1) = "1"
optT(0).Enabled = False
optT(1).Enabled = False

Set tb = DBGEN.OpenRecordset("SELECT * FROM alunni WHERE codice = " & _
frmPrincipale.Keys & " AND anno = '" & txtF(0) & "' AND quad = " & IIf(optT(0), 1, 2), _
dbOpenForwardOnly)

For i = 1 To NumMaterie
If IsNull(tb("4materia" & i)) Then Exit For
lblType(i + 1) = tb("4materia" & i) & ":"
If tb("4materia" & i) <> "Condotta" Then
If Not IsNull(tb("1materia" & i)) Then txtF((i - 1) * 3 + 1) = tb("1materia" & i)
If Not IsNull(tb("2materia" & i)) Then txtF((i - 1) * 3 + 2) = tb("2materia" & i)
If Not IsNull(tb("3materia" & i)) Then txtF(i * 3) = tb("3materia" & i)
Else
If Not IsNull(tb("2materia" & i)) Then txtF((i - 1) * 3 + 2) = tb("2materia" & i)
End If
Next i

If Not IsNull(tb!risultato) Then txtF(46) = tb!risultato
If Not IsNull(tb!debito_prec) Then txtF(47) = tb!debito_prec
If Not IsNull(tb!debito) Then txtF(48) = tb!debito
If Not IsNull(tb!credito) Then txtF(49) = tb!credito

NumTesti = i
Altezza i

If optT(1) Then NascondiTestiSecondo True

End If

Caricamento = False

End Sub

Private Sub optT_Click(Index As Integer)
If Not Caricamento Then NascondiTestiSecondo Index = 1
End Sub

Private Sub txtF_GotFocus(Index As Integer)
With txtF(Index)
.SelStart = 0
.SelLength = Len(txtF(Index))
.BackColor = ColorF
End With
End Sub

Private Sub txtf_KeyPress(Index As Integer, KeyAscii As Integer)
If Index = 0 Then KeyAscii = VerTasto("num", KeyAscii)
If KeyAscii = Asc(".") Then KeyAscii = 0
End Sub

Private Sub txtF_LostFocus(Index As Integer)
txtF(Index).BackColor = ColorNF
If Index = 0 Then
txtF(Index) = VerLostFocus("num", txtF(Index))
If txtF(Index) <> "" Then lblType(27) = "/" & txtF(0) + 1
End If
End Sub

Private Sub Altezza(i As Integer)

i = i - 1
Me.Height = 2460 + i * 375
cmdType(0).Top = 1575 + i * 375
cmdType(1).Top = cmdType(0).Top

While i < NumMaterie
i = i + 1
lblType(i + 1).Visible = False
txtF((i - 1) * 3 + 1).Visible = False
txtF((i - 1) * 3 + 2).Visible = False
txtF(i * 3).Visible = False
Wend

With Me
.Left = (Screen.Width - .Width) \ 2
.Top = (Screen.Height - .Height) \ 2
End With

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then Unload Me
End Sub

Private Sub NascondiTestiSecondo(Tipo As Boolean)
Dim i As Integer

For i = 1 To IIf(NumTesti = 1, 1, (NumTesti - 1)) * 3
If (i + 1) Mod 3 <> 0 Then txtF(i).Visible = Not Tipo
Next i
End Sub