PC Review


Reply
Thread Tools Rate Thread

Can't update records with CurrentUser() control

 
 
charles.kendricks@charter.net
Guest
Posts: n/a
 
      19th May 2007
I have a form which is used to input customer data. The same form
also has a button whose OnClick event causes the form to be
repopulated using a query that prompts for the desired customer last
name...to look up specific customer records. So far, so good. I
recently was asked to monitor who (what users) input or update which
records. So I created two additional fields in the customer records
UpdatedBy, and UpdateTime. I use the BeforeUpdate event of the form
to assign the user and time to those two controls on the form

Private Sub Form_BeforeUpdate(Cancel As Integer)

UpdatedBy = CurrentUser()
UpdateTime = Now()

End Sub

This seems to work fine, also....However when I click the button to
look up the same record that was just created with the form, first of
all the controls on the form don't display the user or time
information that was saved in the record,...and worst of all when I
edit, or change the customer data, such as updat his phone number, and
try to save the record I get a Run-time error that says "You can't
assign a value to this object" when I hit the 'debug' button the
UpdatedBy = CurrentUser() is highlighted.

 
Reply With Quote
 
 
 
 
missinglinq via AccessMonster.com
Guest
Posts: n/a
 
      19th May 2007
>when I click the button to look up the same record that was just created with the form, first of
>all the controls on the form don't display the user or time information that was saved in the record...


Are you still on the record in question when you click the button to look up
the same record again? If so, the record hasn't been saved yet. Me.Dirty =
False will save the data.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via http://www.accessmonster.com

 
Reply With Quote
 
=?Utf-8?B?Q2hlZXNlX3doaXo=?=
Guest
Posts: n/a
 
      19th May 2007
Hi Charles,

What are you doing to 'save' the record before you hit that button? If you
just input a record, or make some changes, those changes aren't 'saved' until
you do something to save them (like navigate to a different record).

You could add this code to the top of the on_click procedure for your button:

Sub YourButton_Click()

If Me.Dirty Then
Me.Dirty = False
End If

'Rest of your on_click code here
End Sub

That also may be the reason you aren't getting the user/time info added.
The 'before_update' event won't fire until you do something to 'update'
(read: save) your added/changed data.

Hope that helps,
CW

"(E-Mail Removed)" wrote:

> I have a form which is used to input customer data. The same form
> also has a button whose OnClick event causes the form to be
> repopulated using a query that prompts for the desired customer last
> name...to look up specific customer records. So far, so good. I
> recently was asked to monitor who (what users) input or update which
> records. So I created two additional fields in the customer records
> UpdatedBy, and UpdateTime. I use the BeforeUpdate event of the form
> to assign the user and time to those two controls on the form
>
> Private Sub Form_BeforeUpdate(Cancel As Integer)
>
> UpdatedBy = CurrentUser()
> UpdateTime = Now()
>
> End Sub
>
> This seems to work fine, also....However when I click the button to
> look up the same record that was just created with the form, first of
> all the controls on the form don't display the user or time
> information that was saved in the record,...and worst of all when I
> edit, or change the customer data, such as updat his phone number, and
> try to save the record I get a Run-time error that says "You can't
> assign a value to this object" when I hit the 'debug' button the
> UpdatedBy = CurrentUser() is highlighted.
>
>

 
Reply With Quote
 
charles.kendricks@charter.net
Guest
Posts: n/a
 
      20th May 2007
I follow the logic of both contributers to my post, and I guess I
should have mentioned that I do close the form after inputting the
data, and I also opened the customer table in table mode to verify
that the new data, including the UpdatedBy, and UpdateTime has been
written successfully to the table. I then re-open the form before
clicking the 'search by name' button.


On May 19, 3:44 pm, "missinglinq via AccessMonster.com" <u28780@uwe>
wrote:
> >when I click the button to look up the same record that was just created with the form, first of
> >all the controls on the form don't display the user or time information that was saved in the record...

>
> Are you still on the record in question when you click the button to look up
> the same record again? If so, the record hasn't been saved yet. Me.Dirty =
> False will save the data.
>
> --
> There's ALWAYS more than one way to skin a cat!
>
> Answers/posts based on Access 2000
>
> Message posted viahttp://www.accessmonster.com



 
Reply With Quote
 
=?Utf-8?B?Q2hlZXNlX3doaXo=?=
Guest
Posts: n/a
 
      20th May 2007
Hi Charles,

If the data is in your table, then your problem is related to the display
controls where you should see the information (updatedby and time). Make
sure the control source of the controls that are suppose to display the data
are properly set to the fields in your table or query. If the controls that
are suppose to display that information (updatedby and time) are NOT in the
main form, make sure that the form they're in has IT'S record source properly
set.

Other than that, I'm not sure what to tell you.

Good Luck,
CW

"(E-Mail Removed)" wrote:

> I follow the logic of both contributers to my post, and I guess I
> should have mentioned that I do close the form after inputting the
> data, and I also opened the customer table in table mode to verify
> that the new data, including the UpdatedBy, and UpdateTime has been
> written successfully to the table. I then re-open the form before
> clicking the 'search by name' button.
>
>
> On May 19, 3:44 pm, "missinglinq via AccessMonster.com" <u28780@uwe>
> wrote:
> > >when I click the button to look up the same record that was just created with the form, first of
> > >all the controls on the form don't display the user or time information that was saved in the record...

> >
> > Are you still on the record in question when you click the button to look up
> > the same record again? If so, the record hasn't been saved yet. Me.Dirty =
> > False will save the data.
> >
> > --
> > There's ALWAYS more than one way to skin a cat!
> >
> > Answers/posts based on Access 2000
> >
> > Message posted viahttp://www.accessmonster.com

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CurrentUser() update. =?Utf-8?B?QW50b25pbw==?= Microsoft Access 2 27th Apr 2007 03:00 AM
CurrentUser to update into table field =?Utf-8?B?YnJlbTIxOQ==?= Microsoft Access Forms 2 7th Oct 2006 07:07 AM
Update a field in all records based on a field control. ernpal@gmail.com Microsoft Access Form Coding 2 6th Dec 2005 04:39 PM
Unbound Control Fields- Add, Update, Save Records Paul Microsoft Access Forms 1 29th Sep 2003 02:02 AM
Linking Master/Child fields with SubForm control but also need CurrentUser?? Neil Microsoft Access Form Coding 3 6th Aug 2003 05:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:02 PM.