Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Lin100
Yak Posting Veteran
70 Posts |
Posted - 2006-08-27 : 20:55:04
|
Access 2003 and SQL 2000 Server.All of the codes below works, and there is no error messages, but 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 & "';"////////////////////////////////////////////////////In SQL Server Enterprise Manager --> Inspection Databae --> User_Account Table -->All Tasks --> Manage Permissionspublic - The check box for SELECT, INSERT, UPDATE, and DELETE are checked////////////////////////////////////////////////////In SQL Server Enterprise Manager --> Security --> Logins -->Win-2000-Server --> Propertiesdb_owner is checkedpublic role is checked''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''THe Table User_Account has the following structureColumn Name Data Type Length Allow NullsName nvarchar 50 0Email_Address nvarchar 50 1P nvarchar 20 1Department_Group nvarchar 50 1Title nvarchar 50 1Access_Status nvarchar 50 1Last_Access_Date nvarchar 50 1The code below does ran without any error but the field "Last_Access_Date" was not updated in table User_Account.This field always remined NULL//////////////////////////////////////////////////////////Private Sub Update_Record_Click() Call User_Login_Using_SQL_String1End Sub//////////////////////////////////////////////////////////Private Sub User_Login_Using_SQL_String1()Dim cnThisConnect As ADODB.ConnectionDim RecordSet_User_Account As New ADODB.RecordsetSet cnThisConnect = CurrentProject.ConnectionDim cmd As ADODB.CommandDim Str_SQL As StringStr_SQL = "SELECT * FROM User_Account WHERE User_Account.Name = '" & Forms!Main_Login!User_Name & "'; "Set cnThisConnect = CurrentProject.ConnectionSet cmd = New ADODB.CommandSet cmd.ActiveConnection = CurrentProject.Connection'cmd.CommandType = adCmdTextRecordSet_User_Account.Open Str_SQL, cnThisConnect, _adOpenKeyset, adLockOptimistic, adCmdTextIf IsNull(Me!User_Name) ThenMsgBox "Please enter your user name", vbInformationExit SubEnd IfIf IsNull(Me!Password) ThenMsgBox "Please enter your password", vbInformationExit SubEnd If'''''''''''''''''''''''''''' RECORDSET CODE BEGINS ''''''''''''''''''''''''If RecordSet_User_Account.RecordCount = 0 ThenMsgBox "The user account does not exist.", vbExclamationElseRecordSet_User_Account.MoveFirstIf RecordSet_User_Account!Name = Me!User_Name ThenIf RecordSet_User_Account!P = Me!Password ThenPublic_Current_User = RecordSet_User_Account!NamePublic_Access_Status = RecordSet_User_Account!Access_Statuscmd.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 , , adCmdTextcmd.CommandText = "UPDATE User_Account " _& "SET Last_Access_Date = '" & Now() & "' " _& "WHERE Name = '" & Forms!Main_Login!User_Name & "';"cmd.Execute , , adAsyncExecuteDoCmd.Close acForm, "Main_Login"DoCmd.OpenForm "Main_Switch_Board"End IfEnd IfEnd IfRecordSet_User_Account.CloseEnd Sub |
|
ijprasad
Starting Member
29 Posts |
Posted - 2006-08-28 : 06:52:59
|
check is any triggers are defined on the table ?Inderjeet |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-28 : 07:02:56
|
What date format do Last_Access_Date have?Peter LarssonHelsingborg, Sweden |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-28 : 11:28:03
|
Why did you use nvarchar datatype to store Dates? use proper DateTime datatypeMadhivananFailing to plan is Planning to fail |
 |
|
Lin100
Yak Posting Veteran
70 Posts |
Posted - 2006-08-29 : 21:49:47
|
No triggers are defined on the table. Last_Access_Date format is nvarchar 50On another table I use nvarchar datatype and it did not gives me any problem. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-30 : 02:40:27
|
Try a debug.print cmd.commandtext to see what is executed.Then do a select from User_Account table with same WHERE clause.Peter LarssonHelsingborg, Sweden |
 |
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2006-08-30 : 12:57:21
|
Lin100,quote: Last_Access_Date format is nvarchar 50On another table I use nvarchar datatype and it did not gives me any problem.
Just because you use it on another table doesn't mean it's right to use it.The DateTime type was specifically designed to hold date/time values. nVarChar and VarChar were designed to hold character data. Use the proper data type for the data you're storing; it will make things much easier for you in the long run.Ken |
 |
|
|
|
|
|
|