Access 2003 and SQL 2000 Server.
Why the field "Last_Access_Date" was not
updated in table User_Account.
cmd.CommandText = "UPDATE User_Account " _
& "SET Last_Access_Date = '" & Now() & "' "& "WHERE Name = '" & Forms!Main_Login!User_Name & "';"
''''''''''''''''''''''''''''''''
THe Table User_Account has the following structure
Column Name Data Type Length Allow Nulls
Name nvarchar 50 0
Email_Address nvarchar 50 1
P nvarchar 20 1
Department_Group nvarchar 50 1
Title nvarchar 50 1
Access_Status nvarchar 50 1
Last_Access_Date nvarchar 50 1
The code below does ran without an error but the
field "Last_Access_Date" was not updated in table User_Account.
//////////////////////////////////////////////////////////
Private Sub Command46_Click()
Call User_Login_Using_SQL_String1
End Sub
//////////////////////////////////////////////////////////
Private Sub User_Login_Using_SQL_String1()
Dim cnThisConnect As ADODB.Connection
Dim RecordSet_User_Account As New ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
Dim cmd As ADODB.Command
Dim Str_SQL As String
Str_SQL = "SELECT * FROM User_Account WHERE User_Account.Name = '" & Forms!Main_Login!User_Name & "'; "
Set cnThisConnect = CurrentProject.Connection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
'cmd.CommandType = adCmdText
RecordSet_User_Account.Open Str_SQL, cnThisConnect, _
adOpenKeyset, adLockOptimistic, adCmdText
If IsNull(Me!User_Name) Then
MsgBox "Please enter your user name", vbInformation
Exit Sub
End If
If IsNull(Me!Password) Then
MsgBox "Please enter your password", vbInformation
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' RECORDSET CODE BEGINS '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If RecordSet_User_Account.RecordCount = 0 Then
MsgBox "The user account does not exist.", vbExclamation
Else
RecordSet_User_Account.MoveFirst
If RecordSet_User_Account!Name = Me!User_Name Then
If RecordSet_User_Account!P = Me!Password Then
Public_Current_User = RecordSet_User_Account!Name
Public_Access_Status = RecordSet_User_Account!Access_Status
cmd.CommandText = "INSERT INTO Table_User_Log_On ( Name, Date_And_Time_Log_On, Department_Group, Access_Status) Values " _
& "('" & RecordSet_User_Account!Name & "', '" & Now() & "', '" & RecordSet_User_Account!Department_Group & "', '" & RecordSet_User_Account!Access_Status & "')"
cmd.Execute , , adCmdText
cmd.CommandText = "UPDATE User_Account " _
& "SET Last_Access_Date = '" & Now() & "' " _
& "WHERE Name = '" & Forms!Main_Login!User_Name & "';"
cmd.Execute , , adAsyncExecute
DoCmd.Close acForm, "Main_Login"
DoCmd.OpenForm "Main_Switch_Board"
End If
End If
End If
RecordSet_User_Account.Close
End Sub
Why the field "Last_Access_Date" was not
updated in table User_Account.
cmd.CommandText = "UPDATE User_Account " _
& "SET Last_Access_Date = '" & Now() & "' "& "WHERE Name = '" & Forms!Main_Login!User_Name & "';"
''''''''''''''''''''''''''''''''
THe Table User_Account has the following structure
Column Name Data Type Length Allow Nulls
Name nvarchar 50 0
Email_Address nvarchar 50 1
P nvarchar 20 1
Department_Group nvarchar 50 1
Title nvarchar 50 1
Access_Status nvarchar 50 1
Last_Access_Date nvarchar 50 1
The code below does ran without an error but the
field "Last_Access_Date" was not updated in table User_Account.
//////////////////////////////////////////////////////////
Private Sub Command46_Click()
Call User_Login_Using_SQL_String1
End Sub
//////////////////////////////////////////////////////////
Private Sub User_Login_Using_SQL_String1()
Dim cnThisConnect As ADODB.Connection
Dim RecordSet_User_Account As New ADODB.Recordset
Set cnThisConnect = CurrentProject.Connection
Dim cmd As ADODB.Command
Dim Str_SQL As String
Str_SQL = "SELECT * FROM User_Account WHERE User_Account.Name = '" & Forms!Main_Login!User_Name & "'; "
Set cnThisConnect = CurrentProject.Connection
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
'cmd.CommandType = adCmdText
RecordSet_User_Account.Open Str_SQL, cnThisConnect, _
adOpenKeyset, adLockOptimistic, adCmdText
If IsNull(Me!User_Name) Then
MsgBox "Please enter your user name", vbInformation
Exit Sub
End If
If IsNull(Me!Password) Then
MsgBox "Please enter your password", vbInformation
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' RECORDSET CODE BEGINS '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If RecordSet_User_Account.RecordCount = 0 Then
MsgBox "The user account does not exist.", vbExclamation
Else
RecordSet_User_Account.MoveFirst
If RecordSet_User_Account!Name = Me!User_Name Then
If RecordSet_User_Account!P = Me!Password Then
Public_Current_User = RecordSet_User_Account!Name
Public_Access_Status = RecordSet_User_Account!Access_Status
cmd.CommandText = "INSERT INTO Table_User_Log_On ( Name, Date_And_Time_Log_On, Department_Group, Access_Status) Values " _
& "('" & RecordSet_User_Account!Name & "', '" & Now() & "', '" & RecordSet_User_Account!Department_Group & "', '" & RecordSet_User_Account!Access_Status & "')"
cmd.Execute , , adCmdText
cmd.CommandText = "UPDATE User_Account " _
& "SET Last_Access_Date = '" & Now() & "' " _
& "WHERE Name = '" & Forms!Main_Login!User_Name & "';"
cmd.Execute , , adAsyncExecute
DoCmd.Close acForm, "Main_Login"
DoCmd.OpenForm "Main_Switch_Board"
End If
End If
End If
RecordSet_User_Account.Close
End Sub