Salve a tutti ^_^ premetto che come programmatore VB sono un newbie
questo e' il codice :
codice:
Private Sub Command2_Click()
If Command2.Caption = "Aggiungi" Then
'Attiva la funzione di aggiunta.
Data1.Recordset.AddNew
Command2.Caption = "Annulla"
Command6.Visible = True
Else
'Annulla le modifiche.
Data1.Recordset.CancelUpdate
Command6.Visible = False
Command2.Caption = "Aggiungi"
End If
End Sub
Private Sub Command4_Click()
Dim Risposta As Integer
'Chiede conferma prima di procedere con l'eliminazione.
Risposta = MsgBox("Eliminare i dati correnti?", vbQuestion + vbYesNo, Me.Caption)
If Risposta = vbYes Then
'Elimina i dati.
Data1.Recordset.Delete
'Si sposta nel record precedente.
Data1.Recordset.MovePrevious
End If
End Sub
Private Sub Command5_Click()
'Aggiorna il controllo.
Data1.Refresh
End Sub
Private Sub Command7_Click()
'Esce dal programma.
Unload Me
End Sub
Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\Agenda.mdb"
End Sub
Private Sub Command3_Click()
If Command3.Caption = "Modifica" Then
'Attiva la funzione di modifica.
Data1.Recordset.Edit
Command3.Caption = "Annulla"
Command6.Visible = True
Else
'Annulla le modifiche.
Data1.Recordset.CancelUpdate
Command6.Visible = False
Command3.Caption = "Modifica"
End If
End Sub
Private Sub Command6_Click()
'Salva le modifiche.
Data1.Recordset.Update
Command6.Visible = False
Command2.Caption = "Aggiungi"
Command3.Caption = "Modifica"
End Sub
Private Sub Data1_Validate(Action As Integer, Save As Integer)
Dim Risposta As Integer
If Save = True Then
'E' stato modificato un contatto.
Risposta = MsgBox("Salvare le modifiche apportate?", vbQuestion + vbYesNo, Me.Caption)
If Risposta = vbNo Then
'Se si seleziona no, annulla le modifiche.
'Per questo, la proprietà DataChanged delle TextBox viene impostata su False.
Text1.DataChanged = False
Text2.DataChanged = False
Text3.DataChanged = False
Text4.DataChanged = False
End If
End If
'Nasconde il pulsante "Salva".
Command6.Visible = False
Command2.Caption = "Aggiungi"
Command3.Caption = "Modifica"
End Sub
Private Sub Command1_Click()
'Ricerca un nome all'interno dell'agenda.
Dim NomeDaCercare As String
NomeDaCercare = InputBox$("Immettere il nome da ricercare:", "Ricerca nell'agenda")
If NomeDaCercare <> "" Then
'Esegue la ricerca solo se è stato immesso un nome.
Data1.Recordset.Index = "Nome"
Data1.Recordset.Seek "=", NomeDaCercare
If Data1.Recordset.NoMatch Then
Data1.Recordset.MoveFirst
Data1.Refresh
'Il nome cercato non è stato trovato.
MsgBox "Nome non trovato.", vbInformation, Me.Caption
End If
End If
End Sub
=======================================
Come vedete e' un semplicissimo code di un programma di RUbrica telefonica,
Il database Agenda.mdb l'ho creato, con tutte le voci, e CHiave primaria su "Nome".
QUando cerco un nome nel database mi da sempre un errore :
Run-Time error 3800
"Nome" non e' un indice di questa tabella.
Magari e' un semplice errore.
VI ringrazio anticipatamente a quanti mi risponderanno
ciauz ^^