User access his own records

G

GL

Hi,

I have multi user database form where a record field takes automatically its
value from the GetCurrentUserName() functions on the On Dirty event.
I want the user who opens the form to be able to edit or delete only the
records that have registered his/her name in the certain field.
Do you have any idea how?

thank you
GL
 
J

Jeff Boyce

One approach would be to add code in the form's BeforeUpdate event that
checks the user's UserName against what was stored for the row and cancels
(?with a message) if they don't match. This has the disadvantage of forcing
the user to complete his/her action and attempt the save/deleted before
being advised.

Another approach would be to only display a user's records (in the
underlying query, select by UserName...). The disadvantage here is that the
user may need to see/read all the messages, not just his/hers.

Yet another possibility would be to create a more general test (is THIS user
the UserName that's recorded) when the form opens, and use the results as a
boolean value to cycle through all the controls on the form, setting the
Enabled property to the boolean value. This would prevent any changes, but
"costs" you the time to develop it.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

GL

Dear Jeff

Thanks for your reply.
I have tried to work out a simple solution based on your third option. So I
put on the form a hidden textbox that reads the user name and stores it.
Then for every textbox or combobox of the form records (displayed in
continuous form view) I used conditional formatting to check if the
expression [RecordUserName]<>Form!FormName!txtCurrentUserName
is valid and enable it or not.
Unfortunately this doesn’t work and records stay always enabled. Do you have
an explanation?

Regards
George
 
J

Jeff Boyce

When is the expression being evaluated? Where is [RecordUserName] coming
from? Is the expression being re-evaluated for each record (e.g., the
OnCurrent event for the form)?

Regards

Jeff Boyce
Microsoft Office/Access MVP


GL said:
Dear Jeff

Thanks for your reply.
I have tried to work out a simple solution based on your third option. So
I
put on the form a hidden textbox that reads the user name and stores it.
Then for every textbox or combobox of the form records (displayed in
continuous form view) I used conditional formatting to check if the
expression [RecordUserName]<>Form!FormName!txtCurrentUserName
is valid and enable it or not.
Unfortunately this doesn't work and records stay always enabled. Do you
have
an explanation?

Regards
George


Jeff Boyce said:
One approach would be to add code in the form's BeforeUpdate event that
checks the user's UserName against what was stored for the row and
cancels
(?with a message) if they don't match. This has the disadvantage of
forcing
the user to complete his/her action and attempt the save/deleted before
being advised.

Another approach would be to only display a user's records (in the
underlying query, select by UserName...). The disadvantage here is that
the
user may need to see/read all the messages, not just his/hers.

Yet another possibility would be to create a more general test (is THIS
user
the UserName that's recorded) when the form opens, and use the results as
a
boolean value to cycle through all the controls on the form, setting the
Enabled property to the boolean value. This would prevent any changes,
but
"costs" you the time to develop it.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

GL

The expression is evaluated in every textbox of the form’s records using
conditional formatting in every one of them.
[RecordUserName] comes from a textbox that exists in every record and holds
the name of the user who has edited that record. The textbox is bound to the
appropriate table’s field.
The expression is evaluated when the form is opened or requeried to set the
textboxes as enabled or disabled.

regards
George

Jeff Boyce said:
When is the expression being evaluated? Where is [RecordUserName] coming
from? Is the expression being re-evaluated for each record (e.g., the
OnCurrent event for the form)?

Regards

Jeff Boyce
Microsoft Office/Access MVP


GL said:
Dear Jeff

Thanks for your reply.
I have tried to work out a simple solution based on your third option. So
I
put on the form a hidden textbox that reads the user name and stores it.
Then for every textbox or combobox of the form records (displayed in
continuous form view) I used conditional formatting to check if the
expression [RecordUserName]<>Form!FormName!txtCurrentUserName
is valid and enable it or not.
Unfortunately this doesn't work and records stay always enabled. Do you
have
an explanation?

Regards
George


Jeff Boyce said:
One approach would be to add code in the form's BeforeUpdate event that
checks the user's UserName against what was stored for the row and
cancels
(?with a message) if they don't match. This has the disadvantage of
forcing
the user to complete his/her action and attempt the save/deleted before
being advised.

Another approach would be to only display a user's records (in the
underlying query, select by UserName...). The disadvantage here is that
the
user may need to see/read all the messages, not just his/hers.

Yet another possibility would be to create a more general test (is THIS
user
the UserName that's recorded) when the form opens, and use the results as
a
boolean value to cycle through all the controls on the form, setting the
Enabled property to the boolean value. This would prevent any changes,
but
"costs" you the time to develop it.

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hi,

I have multi user database form where a record field takes
automatically
its
value from the GetCurrentUserName() functions on the On Dirty event.
I want the user who opens the form to be able to edit or delete only
the
records that have registered his/her name in the certain field.
Do you have any idea how?

thank you
GL
 
J

Jeff Boyce

Conditional formatting? So you are not using the events for the controls or
the form? Give that a try.

I'm guessing you'll need to re-evaluate after each record is loaded. I
don't thing it's enough to do it once when the form loads. Have you tried
re-evaluating via the OnCurrent event?

Regards

Jeff Boyce
Microsoft Office/Access MVP


GL said:
The expression is evaluated in every textbox of the form's records using
conditional formatting in every one of them.
[RecordUserName] comes from a textbox that exists in every record and
holds
the name of the user who has edited that record. The textbox is bound to
the
appropriate table's field.
The expression is evaluated when the form is opened or requeried to set
the
textboxes as enabled or disabled.

regards
George

Jeff Boyce said:
When is the expression being evaluated? Where is [RecordUserName] coming
from? Is the expression being re-evaluated for each record (e.g., the
OnCurrent event for the form)?

Regards

Jeff Boyce
Microsoft Office/Access MVP


GL said:
Dear Jeff

Thanks for your reply.
I have tried to work out a simple solution based on your third option.
So
I
put on the form a hidden textbox that reads the user name and stores
it.
Then for every textbox or combobox of the form records (displayed in
continuous form view) I used conditional formatting to check if the
expression [RecordUserName]<>Form!FormName!txtCurrentUserName
is valid and enable it or not.
Unfortunately this doesn't work and records stay always enabled. Do you
have
an explanation?

Regards
George


:

One approach would be to add code in the form's BeforeUpdate event
that
checks the user's UserName against what was stored for the row and
cancels
(?with a message) if they don't match. This has the disadvantage of
forcing
the user to complete his/her action and attempt the save/deleted
before
being advised.

Another approach would be to only display a user's records (in the
underlying query, select by UserName...). The disadvantage here is
that
the
user may need to see/read all the messages, not just his/hers.

Yet another possibility would be to create a more general test (is
THIS
user
the UserName that's recorded) when the form opens, and use the results
as
a
boolean value to cycle through all the controls on the form, setting
the
Enabled property to the boolean value. This would prevent any
changes,
but
"costs" you the time to develop it.

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hi,

I have multi user database form where a record field takes
automatically
its
value from the GetCurrentUserName() functions on the On Dirty event.
I want the user who opens the form to be able to edit or delete only
the
records that have registered his/her name in the certain field.
Do you have any idea how?

thank you
GL
 
G

GL

Thanks for your help.
I'll quit conditional formattimg and I 'll try something using code.

regards
George

Jeff Boyce said:
Conditional formatting? So you are not using the events for the controls or
the form? Give that a try.

I'm guessing you'll need to re-evaluate after each record is loaded. I
don't thing it's enough to do it once when the form loads. Have you tried
re-evaluating via the OnCurrent event?

Regards

Jeff Boyce
Microsoft Office/Access MVP


GL said:
The expression is evaluated in every textbox of the form's records using
conditional formatting in every one of them.
[RecordUserName] comes from a textbox that exists in every record and
holds
the name of the user who has edited that record. The textbox is bound to
the
appropriate table's field.
The expression is evaluated when the form is opened or requeried to set
the
textboxes as enabled or disabled.

regards
George

Jeff Boyce said:
When is the expression being evaluated? Where is [RecordUserName] coming
from? Is the expression being re-evaluated for each record (e.g., the
OnCurrent event for the form)?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Dear Jeff

Thanks for your reply.
I have tried to work out a simple solution based on your third option.
So
I
put on the form a hidden textbox that reads the user name and stores
it.
Then for every textbox or combobox of the form records (displayed in
continuous form view) I used conditional formatting to check if the
expression [RecordUserName]<>Form!FormName!txtCurrentUserName
is valid and enable it or not.
Unfortunately this doesn't work and records stay always enabled. Do you
have
an explanation?

Regards
George


:

One approach would be to add code in the form's BeforeUpdate event
that
checks the user's UserName against what was stored for the row and
cancels
(?with a message) if they don't match. This has the disadvantage of
forcing
the user to complete his/her action and attempt the save/deleted
before
being advised.

Another approach would be to only display a user's records (in the
underlying query, select by UserName...). The disadvantage here is
that
the
user may need to see/read all the messages, not just his/hers.

Yet another possibility would be to create a more general test (is
THIS
user
the UserName that's recorded) when the form opens, and use the results
as
a
boolean value to cycle through all the controls on the form, setting
the
Enabled property to the boolean value. This would prevent any
changes,
but
"costs" you the time to develop it.

Regards

Jeff Boyce
Microsoft Office/Access MVP


Hi,

I have multi user database form where a record field takes
automatically
its
value from the GetCurrentUserName() functions on the On Dirty event.
I want the user who opens the form to be able to edit or delete only
the
records that have registered his/her name in the certain field.
Do you have any idea how?

thank you
GL
 
J

J. Goddard

Hi -

You could try turning the allowEdits and Allowdeletions properties of
the form on or off in the on current event:

me.allowedits = ( me![recordusername] = [currentusername] )
me.allowdeletions = ( me![recordusername] = [currentusername] )

You could set a public variable to the current user name when the form
is opened; that way you could refer to it anywhere.


HTH

John

Thanks for your help.
I'll quit conditional formattimg and I 'll try something using code.

regards
George

:

Conditional formatting? So you are not using the events for the controls or
the form? Give that a try.

I'm guessing you'll need to re-evaluate after each record is loaded. I
don't thing it's enough to do it once when the form loads. Have you tried
re-evaluating via the OnCurrent event?

Regards

Jeff Boyce
Microsoft Office/Access MVP


The expression is evaluated in every textbox of the form's records using
conditional formatting in every one of them.
[RecordUserName] comes from a textbox that exists in every record and
holds
the name of the user who has edited that record. The textbox is bound to
the
appropriate table's field.
The expression is evaluated when the form is opened or requeried to set
the
textboxes as enabled or disabled.

regards
George

:


When is the expression being evaluated? Where is [RecordUserName] coming
from? Is the expression being re-evaluated for each record (e.g., the
OnCurrent event for the form)?

Regards

Jeff Boyce
Microsoft Office/Access MVP



Dear Jeff

Thanks for your reply.
I have tried to work out a simple solution based on your third option.
So
I
put on the form a hidden textbox that reads the user name and stores
it.
Then for every textbox or combobox of the form records (displayed in
continuous form view) I used conditional formatting to check if the
expression [RecordUserName]<>Form!FormName!txtCurrentUserName
is valid and enable it or not.
Unfortunately this doesn't work and records stay always enabled. Do you
have
an explanation?

Regards
George


:


One approach would be to add code in the form's BeforeUpdate event
that
checks the user's UserName against what was stored for the row and
cancels
(?with a message) if they don't match. This has the disadvantage of
forcing
the user to complete his/her action and attempt the save/deleted
before
being advised.

Another approach would be to only display a user's records (in the
underlying query, select by UserName...). The disadvantage here is
that
the
user may need to see/read all the messages, not just his/hers.

Yet another possibility would be to create a more general test (is
THIS
user
the UserName that's recorded) when the form opens, and use the results
as
a
boolean value to cycle through all the controls on the form, setting
the
Enabled property to the boolean value. This would prevent any
changes,
but
"costs" you the time to develop it.

Regards

Jeff Boyce
Microsoft Office/Access MVP



Hi,

I have multi user database form where a record field takes
automatically
its
value from the GetCurrentUserName() functions on the On Dirty event.
I want the user who opens the form to be able to edit or delete only
the
records that have registered his/her name in the certain field.
Do you have any idea how?

thank you
GL
 
Top