codice:Option Explicit Dim NuovoModifica As String Private Sub cmdEliminaAnnulla_Click() If cmdEliminaAnnulla.Caption = "E L I M I N A" Then cmdNuovoConferma.Caption = "N U O V O" cmdEliminaAnnulla.Caption = "E L I M I N A" Dim Elimina1 Dim Elimina2 Elimina1 = MsgBox("Vuoi eliminare il record corrente?", vbYesNo) If Elimina1 = vbYes Then Elimina2 = MsgBox("Il record corrente sarà eliminato definitivamente.", vbYesNo) If Elimina2 = vbYes Then On Error Resume Next adoComuni.Recordset.Delete adoComuni.Recordset.Update End If End If End If If cmdEliminaAnnulla.Caption = "A N N U L L A" Then cmdNuovoConferma.Caption = "N U O V O" cmdEliminaAnnulla.Caption = "E L I M I N A" txtComune.Text = "" txtTelefono.Text = "" txtFax.Text = "" txtNota.Text = "" txtComune.Locked = True txtTelefono.Locked = True txtFax.Locked = True txtNota.Locked = True txtComune.SetFocus End If End Sub Private Sub cmdModifica_Click() NuovoModifica = "M" txtComune.Locked = False txtTelefono.Locked = False txtFax.Locked = False txtNota.Locked = False cmdNuovoConferma.Caption = "C O N F E R M A" cmdEliminaAnnulla.Caption = "A N N U L L A" cmdModifica.Enabled = False txtComune.SetFocus End Sub Private Sub cmdNuovoConferma_Click() If cmdNuovoConferma.Caption = "N U O V O" Then NuovoModifica = "N" txtComune.Locked = False txtTelefono.Locked = False txtFax.Locked = False txtNota.Locked = False txtComune.Text = "" txtTelefono.Text = "" txtFax.Text = "" txtNota.Text = "" cmdNuovoConferma.Caption = "C O N F E R M A" cmdEliminaAnnulla.Caption = "A N N U L L A" cmdEliminaAnnulla.Enabled = True cmdModifica.Enabled = False txtComune.SetFocus Exit Sub End If If cmdNuovoConferma.Caption = "C O N F E R M A" Then cmdNuovoConferma.Caption = "N U O V O" cmdEliminaAnnulla.Caption = "A N N U L L A" cmdModifica.Enabled = True With adoComuni If NuovoModifica = "N" Then .Recordset.AddNew End If .Recordset("Comune") = txtComune.Text .Recordset("Telefono") = txtTelefono.Text .Recordset("Fax") = txtFax.Text .Recordset("Nota") = txtNota.Text .Recordset.Update dtgComuni.Refresh End With cmdEliminaAnnulla.Caption = "E L I M I N A" txtComune.Locked = True txtTelefono.Locked = True txtFax.Locked = True txtNota.Locked = True End If End Sub Private Sub cmdRimuoviFiltro_Click() txtFiltroComune.Text = "" End Sub Private Sub dtgComuni_RowColChange(LastRow As Variant, ByVal LastCol As Integer) On Error Resume Next txtComune.Text = adoComuni.Recordset("Comune") txtTelefono.Text = adoComuni.Recordset("Telefono") txtFax.Text = adoComuni.Recordset("Fax") txtNota.Text = adoComuni.Recordset("Nota") adoComuni.Caption = "SONO STATI TROVATI " & adoComuni.Recordset.RecordCount & " COMUNI." End Sub Private Sub Form_Load() adoComuni.Caption = "SONO STATI TROVATI " & adoComuni.Recordset.RecordCount & " COMUNI." End Sub Private Sub lblComune_Click() adoComuni.Recordset.Sort = "Comune ASC" End Sub Private Sub lblFax_Click() adoComuni.Recordset.Sort = "Fax ASC" End Sub Private Sub lblTelefono_Click() adoComuni.Recordset.Sort = "Telefono ASC" End Sub Private Sub txtComune_Change() If txtComune.Text <> "" Then cmdEliminaAnnulla.Enabled = True cmdModifica.Enabled = True Else cmdEliminaAnnulla.Enabled = False cmdModifica.Enabled = False End If End Sub Private Sub txtFiltroComune_Change() adoComuni.Recordset.Filter = adFilterNone If txtFiltroComune.Text = "" Then adoComuni.Recordset.Filter = "Comune <> ''" Else On Error Resume Next adoComuni.Recordset.Filter = "Comune Like '*" & txtFiltroComune.Text & "*'" End If If adoComuni.Recordset.RecordCount = 0 Then txtComune.Text = "" txtTelefono.Text = "" txtFax.Text = "" txtNota.Text = "" End If End Sub