dbTalk Databases Forums  

Form button code that deletes value based on field that is focused

comp.databases.ms-access comp.databases.ms-access


Discuss Form button code that deletes value based on field that is focused in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AA Arens
 
Posts: n/a

Default Form button code that deletes value based on field that is focused - 08-01-2009 , 02:15 AM






I am looking for a way to delete the value from either a textbox or
combo box by a button on a form and the action to delete applies to
the textbox or combo that is focused with the mouse.
The delete action is followed by a record refresh, implicating
dependent fields become empty or unable (already works)

Bart

Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: Form button code that deletes value based on field that is focused - 08-01-2009 , 05:08 AM






The problem here is that when the user clicks the button on your form, the
field loses focus (i.e. focus moves to the command button when you click
it.)

You may be able to use:
Screen.PreviousControl = Null
but several things could go wrong here, e.g.:
- there might not be a previous control,
- the previous control may not hold data (e.g. another command button)
- the previous control may be bound to a required field (so cannot be set to
Null.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"AA Arens" <bartvandongen (AT) gmail (DOT) com> wrote

Quote:
I am looking for a way to delete the value from either a textbox or
combo box by a button on a form and the action to delete applies to
the textbox or combo that is focused with the mouse.
The delete action is followed by a record refresh, implicating
dependent fields become empty or unable (already works)

Bart

Reply With Quote
  #3  
Old   
AA Arens
 
Posts: n/a

Default Re: Form button code that deletes value based on field that isfocused - 08-01-2009 , 05:19 AM



On Aug 1, 5:08*pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote:
Quote:
The problem here is that when the user clicks the button on your form, the
field loses focus (i.e. focus moves to the command button when you click
it.)

You may be able to use:
* * Screen.PreviousControl = Null
but several things could go wrong here, e.g.:
- there might not be a previous control,
- the previous control may not hold data (e.g. another command button)
- the previous control may be bound to a required field (so cannot be setto
Null.)

--
Allen Browne - Microsoft MVP. *Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"AA Arens" <bartvandon... (AT) gmail (DOT) com> wrote in message

news:2027bec3-22a5-4f3e-aaa8-fb3320cdc277 (AT) i18g2000pro (DOT) googlegroups.com...

I am looking for a way to delete the value from either a textbox or
combo box by a button on a form and the action to delete applies to
the textbox or combo that is focused with the mouse.
The delete action is followed by a record refresh, implicating
dependent fields become empty or unable (already works)

Bart
Allen,

Based on your input, it's better to have a button beside the field it
refers to, so for every field an "erase value" button.

What would be the code, I remember such as erase function but I can't
find a good sample.

Bart

Reply With Quote
  #4  
Old   
Allen Browne
 
Posts: n/a

Default Re: Form button code that deletes value based on field that is focused - 08-01-2009 , 07:36 AM



The button for City would be:
Me.City = Null

But you still have the problem where the field might be required.

How about teaching the users to press the Esc key once to undo the current
field, or twice to undo the record?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"AA Arens" <bartvandongen (AT) gmail (DOT) com> wrote

On Aug 1, 5:08 pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote:
Quote:
The problem here is that when the user clicks the button on your form, the
field loses focus (i.e. focus moves to the command button when you click
it.)

You may be able to use:
Screen.PreviousControl = Null
but several things could go wrong here, e.g.:
- there might not be a previous control,
- the previous control may not hold data (e.g. another command button)
- the previous control may be bound to a required field (so cannot be set
to
Null.)

"AA Arens" <bartvandon... (AT) gmail (DOT) com> wrote in message

news:2027bec3-22a5-4f3e-aaa8-fb3320cdc277 (AT) i18g2000pro (DOT) googlegroups.com...

I am looking for a way to delete the value from either a textbox or
combo box by a button on a form and the action to delete applies to
the textbox or combo that is focused with the mouse.
The delete action is followed by a record refresh, implicating
dependent fields become empty or unable (already works)

Bart
Allen,

Based on your input, it's better to have a button beside the field it
refers to, so for every field an "erase value" button.

What would be the code, I remember such as erase function but I can't
find a good sample.

Bart

Reply With Quote
  #5  
Old   
Salad
 
Posts: n/a

Default Re: Form button code that deletes value based on field that is focused - 08-01-2009 , 09:30 AM



AA Arens wrote:
Quote:
On Aug 1, 5:08 pm, "Allen Browne" <AllenBro... (AT) SeeSig (DOT) Invalid> wrote:

The problem here is that when the user clicks the button on your form, the
field loses focus (i.e. focus moves to the command button when you click
it.)

You may be able to use:
Screen.PreviousControl = Null
but several things could go wrong here, e.g.:
- there might not be a previous control,
- the previous control may not hold data (e.g. another command button)
- the previous control may be bound to a required field (so cannot be set to
Null.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"AA Arens" <bartvandon... (AT) gmail (DOT) com> wrote in message

news:2027bec3-22a5-4f3e-aaa8-fb3320cdc277 (AT) i18g2000pro (DOT) googlegroups.com...


I am looking for a way to delete the value from either a textbox or
combo box by a button on a form and the action to delete applies to
the textbox or combo that is focused with the mouse.
The delete action is followed by a record refresh, implicating
dependent fields become empty or unable (already works)

Bart


Allen,

Based on your input, it's better to have a button beside the field it
refers to, so for every field an "erase value" button.

What would be the code, I remember such as erase function but I can't
find a good sample.

Bart
Could you do this?

Option Compare Database
Option Explicit
Dim strField As String
Private Function GetName()
strField = Me.ActiveControl.Name
MsgBox strField 'for debugging purposes only
End Function

Then your command buttons code could be
Me(strField) = Null

In design view of the form, hightlight all the fields you want to clear
and enter the property sheet. In the OnGotFocus event enter
=GetName()

Caveat. If you had GetName() in address but not in city, and were
sitting in city and then pressed the button, address would be wiped out.

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.