Hai ragione.. Non l'ho postato perchè un po' lungo...
Comunque eccolo, questa è la routine dell'evento Click sul Button che vonferma l'inserimento nel DB del nuovo record:
codice:
Private Sub pulsok_Click()
Dim ok As Boolean
ok = False
If Option1.Value = True And Len(txtval1.Text) > 0 And Len(txtarea.Text) > 0 Then
ok = True
End If
If Option1.Value = False And Len(txtval1.Text) > 0 And Len(txtval2.Text) > 0 And Len(txtarea.Text) > 0 Then
ok = True
End If
If ok Then
sql = "ambindicatori"
rs.Open sql, cn, 3, 3
rs.AddNew
rs("area") = txtarea.Text
If Option1.Value Then rs("tipo") = "Fisso"
If Option2.Value Then rs("tipo") = "Rapporto"
If Option3.Value Then rs("tipo") = "Prodotto"
If Option4.Value Then rs("tipo") = "Somma"
If Option5.Value Then rs("tipo") = "Sottrazione"
If Option6.Value Then rs("tipo") = "Variazione %"
rs("nome1") = txtval1.Text
rs("nome2") = txtval2.Text
rs("tobi") = cmbobi.Text
rs("obi") = txtobi.Text
rs("cad") = cmbcad.Text
If Len(txtgg.Text) > 0 Then
rs("cadgg") = txtgg.Text
End If
rs.Update
rs.Close
aggiorna
Unload ambinsind
Else
MsgBox "I campi ""Descrizione Area"" e ""Descrizione Primo Valore"" sono obbligatori, per gli indicatori di tipo NON fisso è obbligatorio anche il campo ""Descrizione Secondo Valore""", vbExclamation
End If
End Sub
E questa è la funzione "aggiorna" che viene chiamata nella routine qui sopra, è quella che dovrebbe aggiornare la listview (listind) dell'altro form (ambipa), ma non lo fa..
codice:
Function aggiorna()
sql = "SELECT * FROM ambindicatori ORDER BY cont"
ambipa.listind.ListItems.Clear
rs.Open sql, cn, 3, 3
Do While Not rs.EOF
Dim li As ListItem
Set li = ambipa.listind.ListItems.Add(, , rs("cont"))
li.ListSubItems.Add , , rs("area")
If Len(rs("nome2")) > 0 Then
Select Case rs("tipo")
Case "Rapporto": li.ListSubItems.Add , , rs("nome1") & " / " & rs("nome2")
Case "Prodotto": li.ListSubItems.Add , , rs("nome1") & " * " & rs("nome2")
Case "Somma": li.ListSubItems.Add , , rs("nome1") & " + " & rs("nome2")
Case "Sottrazione": li.ListSubItems.Add , , rs("nome1") & " - " & rs("nome2")
End Select
Else
li.ListSubItems.Add , , rs("nome1")
End If
If Len(rs("tobi")) > 0 And Len(rs("obi") > 0) Then
li.ListSubItems.Add , , rs("tobi") & " " & rs("obi")
Else
li.ListSubItems.Add , , "..."
End If
li.ListSubItems.Add , , rs("cad")
rs.MoveNext
Loop
rs.Close
End Function
Il DB viene aggiornato perchè se chiudo e riapro il form con la listview quest'ultima comprende anche il record appena immesso...
Grazie mille per l'aiuto..