codice:
Private Sub cmdSalva_Click()
' CONTROLLO LA VALIDITA' DEI CAMPI
If Len(Trim(ragione_sociale.Text)) = 0 Then
lblMessaggio.Caption = "Inserire la ragione sociale"
ragione_sociale.SetFocus
ElseIf Len(Trim(indirizzo.Text)) = 0 Then
lblMessaggio.Caption = "Inserire indirizzo"
indirizzo.SetFocus
ElseIf Len(Trim(citta.Text)) = 0 Then
lblMessaggio.Caption = "Inserire citta"
citta.SetFocus
ElseIf Len(Trim(provincia.Text)) = 0 Then
lblMessaggio.Caption = "Inserire provincia"
provincia.SetFocus
ElseIf Len(Trim(cap.Text)) = 0 Then
lblMessaggio.Caption = "Inserire cap"
cap.SetFocus
ElseIf Len(Trim(nazione.Text)) = 0 Then
lblMessaggio.Caption = "Inserire nazione"
nazione.SetFocus
ElseIf Len(Trim(p_iva.Text)) = 0 Then
lblMessaggio.Caption = "Inserire partita iva"
p_iva.SetFocus
ElseIf Len(Trim(cod_fiscale.Text)) = 0 Then
lblMessaggio.Caption = "Inserire cod fiscale"
cod_fiscale.SetFocus
ElseIf Len(Trim(telefono.Text)) = 0 Then
lblMessaggio.Caption = "Inserire telefono"
telefono.SetFocus
ElseIf Len(Trim(fax.Text)) = 0 Then
lblMessaggio.Caption = "Inserire fax"
fax.SetFocus
ElseIf Len(Trim(email.Text)) = 0 Then
lblMessaggio.Caption = "Inserire email"
email.SetFocus
ElseIf Len(Trim(http.Text)) = 0 Then
lblMessaggio.Caption = "Inserire http"
http.SetFocus
Else ' SE TUTTE LE CONDIZIONI SONO STATE SODDISFATTE...
' COMANDO SQL A SECONDA CHE SI TRATTI DI UNA INSERT O DI UN UPDATE
Dim SQL As String
' MESSAGGIO DI CONFERMA (SECONDO LO STESSO CRITERIO DESCRITTO SOPRA)
Dim conferma As String
' COME SOPRA...
s = Split(cmbSeleziona.Text, " ")
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
' APRO LA CONNESSIONE E LANCIO LA QUERY PER RECUPERARE I DATI
'Apro la connessione.
Const Provider As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\paghe.mdb"
cn.Open Provider
If cmbSeleziona.Text = "" Then ' ...ESEGUO LA INSERT
SQL = "INSERT INTO clienti " _
& "(nome, indirizzo, citta, provincia, cap, nazione, iva, codicefiscale, telefono, fax, email, http) " _
& "VALUES " _
& "('" & Replace(ragione_sociale.Text, "'", "''") & "', " _
& "'" & Replace(indirizzo.Text, "'", "''") & "'," _
& "'" & Replace(citta.Text, "'", "''") & "'," _
& "'" & Replace(provincia.Text, "'", "''") & "'," _
& "'" & Replace(cap.Text, "'", "''") & "'," _
& "'" & Replace(nazione.Text, "'", "''") & "'," _
& "'" & Replace(p_iva.Text, "'", "''") & "'," _
& "'" & Replace(cod_fiscale.Text, "'", "''") & "'," _
& "'" & Replace(telefono.Text, "'", "''") & "'," _
& "'" & Replace(fax.Text, "'", "''") & "'," _
& "'" & Replace(email.Text, "'", "''") & "'," _
& "'" & Replace(http.Text, "'", "''") & "')"
conferma = "Inserimento effettuato con successo"
Else ' ...ESEGUO L'UPDATE
SQL = "UPDATE clienti SET " _
& "nome = '" & Replace(ragione_sociale.Text, "'", "''") & "', " _
& "indirizzo = '" & Replace(indirizzo.Text, "'", "''") & "' " _
& "citta = '" & Replace(citta.Text, "'", "''") & "' " _
& "provincia = '" & Replace(provincia.Text, "'", "''") & "' " _
& "cap = '" & Replace(cap.Text, "'", "''") & "' " _
& "nazione = '" & Replace(nazione.Text, "'", "''") & "' " _
& "iva = '" & Replace(p_iva.Text, "'", "''") & "' " _
& "codicefiscale = '" & Replace(cod_fiscale.Text, "'", "''") & "' " _
& "telefono = '" & Replace(telefono.Text, "'", "''") & "' " _
& "fax = '" & Replace(fax.Text, "'", "''") & "' " _
& "email = '" & Replace(email.Text, "'", "''") & "' " _
& "http = '" & Replace(http.Text, "'", "''") & "' " _
& "WHERE id = " & CInt(s(0))
conferma = "Modifica effettuata con successo"
End If
' ESEGUO IL COMANDO SQL CHE ARRIVA DELLA CONDIZIONE
cn.Execute (SQL)
lblMessaggio.Caption = conferma
cn.Close
' PULISCO E RICARICO LA COMBO BOX
cmbSeleziona.Clear
Call Form_Load
End If
End Sub