Questa la versione funzionante con qualche lieve modifica, ma Mimmo57 è stato bravissimo
Private Sub cmdOK_Click()
On Error GoTo ErrorHandler
Dim db As DAO.Database
Dim sql As String
Dim rst As DAO.Recordset
If Len("" & Me.txtNomeUtente.Value) = 0 Or Len("" & Me.txtPassword.Value) = 0 Then
MsgBox "Inserire Nome Utente e Password!"
Else
Set db = CurrentDb
sql = "SELECT *" & _
" FROM Nomi" & _
" WHERE [Nome utente]='" & Me.txtNomeUtente.Value & "';"
Set rst = db.OpenRecordset(sql)
With rst
If .BOF And .EOF Then
' Nessun record
Else
mblnOk = .Fields("Password").Value = Me.txtPassword.Value
End If
End With
If mblnOk Then
DoCmd.RunSQL "INSERT INTO Table1 ( Login, Inizio, Fine ) SELECT '" & Me.txtNomeUtente & "', Now(), Null"
MsgBox "OK" '<--- Sostituire con apertura maschera principale ---
Else
MsgBox "Nome Utente inesistente o Password errata."
End If
End If
ExitProcedure:
On Error Resume Next
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub
End Sub
Private Sub Form_Close()
If mblnOk Then
DoCmd.RunSQL "Update Table1 Set Fine = Now() Where Login = '" & Me.txtNomeUtente & "' And Fine Is Null"
Else
Me.Application.Quit
End If
End Sub
L'unica cosa però non si chiude l'applicazione, ma solo la maschera di accesso, e inoltre si può incrementare anche con la registrazione di una operazione tipo l'apertura di una maschera ?
Un'altra cosa mi conviene far aprire il database o unire il database di accesso con tutto il resto ?