Clearing value in a control

  • Thread starter Thread starter google3luo359
  • Start date Start date
G

google3luo359

Hello, I would like to clear the value in a control on a form that is
open (Form1)
Form1 stays open while work is done on a second form, Form2.
When Form2 is closed I would like to clear the value in the control on
Form1.

I tried:
Forms![frmPass]![txtPassword] = ""

It worked; when I returned to Form1, the control had been cleared but
when I tried to enter data into the control I received this error:

The data has been changed. Another user edited this record and saved
the changes before you attempted to save your changes. Re-edit the
record. OK.

I can, edit the control after clearing this error message but would
like to avoid getting the error message.
I tried putting 'DoCmd.SetWarnings False' into OnEnter and OnChange
Events, but it didn't help.

Is there a more effective way to clear the control AND not have error
messages occur?

TIA Ric
 
Hi, Ric.
The data has been changed. Another user edited this record and saved
the changes before you attempted to save your changes. Re-edit the
record.

Save the current record on Form1 before opening Form2.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


Hello, I would like to clear the value in a control on a form that is
open (Form1)
Form1 stays open while work is done on a second form, Form2.
When Form2 is closed I would like to clear the value in the control on
Form1.

I tried:
Forms![frmPass]![txtPassword] = ""

It worked; when I returned to Form1, the control had been cleared but
when I tried to enter data into the control I received this error:

The data has been changed. Another user edited this record and saved
the changes before you attempted to save your changes. Re-edit the
record. OK.

I can, edit the control after clearing this error message but would
like to avoid getting the error message.
I tried putting 'DoCmd.SetWarnings False' into OnEnter and OnChange
Events, but it didn't help.

Is there a more effective way to clear the control AND not have error
messages occur?

TIA Ric
 
'69 Camaro said:
Hi, Ric.


Save the current record on Form1 before opening Form2.


That sounded like a good idea. Maybe I'm not saving properly?
Here's what I tried for code under the button that launches Form2:

Private Sub SetPass_Click()
On Error GoTo Err_SetPass_Click

Dim stDocName As String
Dim stLinkCriteria As String

DoCmd.Save
stDocName = "frmPassSet"
DoCmd.OpenForm stDocName, , , stLinkCriteria

But when I returned to Form1 I still got the error when trying to enter
data in the control.

Ric
 
Hi, Ric.
Maybe I'm not saving properly?

You hit the nail on the head! DoCmd.Save saves the specified object or the
active object, which is Form1, not the current record. You have several
choices for how to save the record. Two are one-liners. Try both of these
methods below and see which one you like better:

RunCommand acCmdSaveRecord
stDocName = "frmPassSet"
DoCmd.OpenForm stDocName, , , stLinkCriteria

.. . . or:

Me.Dirty = True
stDocName = "frmPassSet"
DoCmd.OpenForm stDocName, , , stLinkCriteria

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
Maybe I'm not saving properly?
You hit the nail on the head! DoCmd.Save saves the specified object or the
active object, which is Form1, not the current record. You have several
choices for how to save the record. Two are one-liners. Try both of these
methods below and see which one you like better:

RunCommand acCmdSaveRecord
stDocName = "frmPassSet"
DoCmd.OpenForm stDocName, , , stLinkCriteria

. . . or:

Me.Dirty = True
stDocName = "frmPassSet"
DoCmd.OpenForm stDocName, , , stLinkCriteria

HTH.
Gunny


It looks like we're going to have to bring out the big guns, Gunny for
this one! :)
I tried each of your suggestions but couldn't get either to work.

RunCommand acCmdSaveRecord produced the same error as before.
Me.Dirty = True produced this error:

"In order to change data through this form, the focus must be in a
bound field that can be modified. OK"

There are only two controls on Form1 and they are both Unbound.

Hmmmmm............... there must be a way.

Ric
 
Gunny is a big gun, but I think that was meant to be:

Me.Dirty = False

But, if there are no bound controls, there isn't anything to
save, is there???
 
Marshall said:
Gunny is a big gun, but I think that was meant to be:

Me.Dirty = False

But, if there are no bound controls, there isn't anything to
save, is there???


Thanks for helping out Marsh!
But, if there are no bound controls, there isn't anything to
save, is there???

I guess not. But why then does Access throw this message at me:

"The data has been changed. Another user edited this record and saved
the changes before you attempted to save your changes. Re-edit the
record. OK. "

And it's not even an accurate error message. I start on this form
(Form1) and go to Form2 where a record is 'dirtied'. Then I return to
Form1 and nothing is ever saved (no user "saved the changes").
So is there no way to clear this unbound control without having this
error message come up every time?

TIA Ric
 
I guess not. But why then does Access throw this message at me:

"The data has been changed. Another user edited this record and saved
the changes before you attempted to save your changes. Re-edit the
record. OK. "

And it's not even an accurate error message. I start on this form
(Form1) and go to Form2 where a record is 'dirtied'. Then I return to
Form1 and nothing is ever saved (no user "saved the changes").
So is there no way to clear this unbound control without having this
error message come up every time?


All this is making no sense to me. I would **guess** that
you should remove the form's RecordSource (if it has one)
and make sure you don't have some extraneous code behind the
form that's getting in the way.

Failing all that, just in case you've got some kind of
corruption going on, try creating a new, empty database and
Importing everything from the original database.
 
Marshall said:
All this is making no sense to me. I would **guess** that
you should remove the form's RecordSource (if it has one)
and make sure you don't have some extraneous code behind the
form that's getting in the way.
Marsh
MVP [MS Access]


Brilliant! That did it!
Not knowing any better, I did have a RecordSource set and that was
obviously screwing things up in this case. (must make mental note for
future ......)

Thanks very much Marsh!

Ric
 
Thanks, Marsh. Yes, I goofed. Thanks for catching that.

Gunny


Marshall Barton said:
Gunny is a big gun, but I think that was meant to be:

Me.Dirty = False

But, if there are no bound controls, there isn't anything to
save, is there???
--
Marsh
MVP [MS Access]


It looks like we're going to have to bring out the big guns, Gunny for
this one! :)
I tried each of your suggestions but couldn't get either to work.

RunCommand acCmdSaveRecord produced the same error as before.
Me.Dirty = True produced this error:

"In order to change data through this form, the focus must be in a
bound field that can be modified. OK"

There are only two controls on Form1 and they are both Unbound.
 
Hi, Ric.

I've been away from the computer for a little while, and when I came back
and started reading the newer posts to this thread, I was about to post that
you should become a detective and find the code that was using a Recordset
object and had an AddNew or Edit method executed without an Update method
executed before Form2 was opened. But it looks like Marsh had everything
under control. Way to go, Marsh!

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


Marshall said:
All this is making no sense to me. I would **guess** that
you should remove the form's RecordSource (if it has one)
and make sure you don't have some extraneous code behind the
form that's getting in the way.
Marsh
MVP [MS Access]


Brilliant! That did it!
Not knowing any better, I did have a RecordSource set and that was
obviously screwing things up in this case. (must make mental note for
future ......)

Thanks very much Marsh!

Ric
 
You're welcome, Gunny, but we all slip a mental gear every
once in a while so we all try to watch eact other's back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top