Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update Field to current logged in user ID with new record command button


Update Field to current logged in user ID with new record command button

Author
Message
kwoznica
kwoznica
SSC Veteran
SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)

Group: General Forum Members
Points: 221 Visits: 475
Also here is the complete table definition.


USE [GKHumanResource]
GO

/****** Object: Table [dbo].[HRCaseData] Script Date: 8/7/2013 3:59:59 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[HRCaseData](
[Id] [int] IDENTITY(100,1) NOT NULL,
[CaseDate] [date] NOT NULL,
[Customer] [varchar](50) NOT NULL,
[HrRepId] [varchar](50) NOT NULL,
[Category] [int] NOT NULL,
[CaseDescription] [varchar](30) NOT NULL,
[CaseStatus] [bit] NOT NULL,
[ClosedDate] [date] NULL,
[Resolution] [varchar](1000) NULL,
[DepartmentID] [smallint] NOT NULL,
CONSTRAINT [PK_ID_Customer_Category] PRIMARY KEY CLUSTERED
(
[Id] ASC,
[Customer] ASC,
[Category] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[HRCaseData] ADD CONSTRAINT [DF_HRCaseData_HrRepId] DEFAULT (suser_sname()) FOR [HrRepId]
GO

ALTER TABLE [dbo].[HRCaseData] ADD DEFAULT ((7)) FOR [DepartmentID]
GO

ALTER TABLE [dbo].[HRCaseData] WITH CHECK ADD CONSTRAINT [FK_Category_CatType] FOREIGN KEY([Category])
REFERENCES [dbo].[HRCategory] ([ID])
GO

ALTER TABLE [dbo].[HRCaseData] CHECK CONSTRAINT [FK_Category_CatType]
GO

ALTER TABLE [dbo].[HRCaseData] WITH CHECK ADD CONSTRAINT [FK_Department] FOREIGN KEY([DepartmentID])
REFERENCES [dbo].[HRDepartment] ([DepartmentID])
GO

ALTER TABLE [dbo].[HRCaseData] CHECK CONSTRAINT [FK_Department]
GO




WendellB
WendellB
SSC Veteran
SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)

Group: General Forum Members
Points: 247 Visits: 1633
There should not be any difference based on SQL Server version or Access version. This technique is dependant only on SQL Server, and we have similar tables that work just fine on both versions you mention.

On permissions, we normally give each user dbowner on the database so that we don't have to set permissions on all of the objects - as in general our users should be able to update all the tables. (We do restrict users by presenting the data in forms and do not give them access to the tables.)

Just a hunch, but by chance are they using an Access form to add records that has a different default value set for that field? That seems to me to be the most logical explanation for the behavior you are seeing. To test that you could try adding a record to the table directly without using an Access form. Another more remote possibility is that there is an issue with the UserName in SQL Server - is this Integrated Security or SQL Server Security? Also it would help to know if the field is truly a Null, a series of blank characters, or an empty text string.

Wendell
Colorful Colorado
You can't see the view if you don't climb the mountain!
kwoznica
kwoznica
SSC Veteran
SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)SSC Veteran (221 reputation)

Group: General Forum Members
Points: 221 Visits: 475
Sorry for the false alarm. It was me being a fool. When I added the ODBC connection from access I was importing the data instead of choosing linking. Once I changed that about 3 hours of banging my head against the wall was all due to a simple over sight.

It is working very well now. Thanks for your help.
sumanth.pathuri
sumanth.pathuri
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 11
How can we capture if someone edits a record without using a trigger. We need a column in the same table. Can you please help me with this.
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14955 Visits: 38949
sumanth.pathuri (1/11/2017)
How can we capture if someone edits a record without using a trigger. We need a column in the same table. Can you please help me with this.


you should start a new thread to get the best help, since this thread is four years old or so. also, the forum is related to Access, but you really mean SQL, right?

so are you sure you want to paint yourself in a corner with a rule that says absolutely, positively, without a trigger AND you need whodunnit information?

a trigger is the best way to handle that requirement, i would say.

For data changes, you can use SQL Temporal Tables, Change Data Capture to track what specific data changed, Change Tracking to capture which data changed, but neither has who did it information.

For whodunnit changes, SQL Audit or an Extended event has who changed the data, but not the details of which specific data was changed.

I'm under the impression that the only place for both data and user info is at the trigger level, unless someone can correct me on my conceptions/misconceptions.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

WendellB
WendellB
SSC Veteran
SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)SSC Veteran (247 reputation)

Group: General Forum Members
Points: 247 Visits: 1633
sumanth.pathuri (1/11/2017)
How can we capture if someone edits a record without using a trigger. We need a column in the same table. Can you please help me with this.
As this is a rather old thread, are you working in the same situation as the original poster? That is, are you working with ODBC linked tables in an Access front-end? Or are you working with an Access ADP that connects directly to SQL Server? Also the versions may be important. In the first case, you can create VBA procedures that are initiated by the OnChange event of the form that update a last changed field, assuming that your form is bound to a table source. However if you allow editing at the table level, and at least some users will probably have that capability, then using triggers is the only effective way we have found to track who and when a record was last changed.

Wendell
Colorful Colorado
You can't see the view if you don't climb the mountain!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search