UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Set And Save Default Value In The Textbox, Access 2010    
 
   
zozzz
post Jul 16 2017, 01:10 PM
Post#1



Posts: 44
Joined: 29-January 15



hi everyone

I am using Me.Text2.DefaultValue = "David"
But whenever I opened The form my default text (David) is clean

How can I save it ???
Go to the top of the page
 
theDBguy
post Jul 16 2017, 01:30 PM
Post#2


Access Wiki and Forums Moderator
Posts: 70,270
Joined: 19-June 07
From: SunnySandyEggo


Try,

DoCmd.Close acForm, Me.Name, acSaveYes

Just a thought...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
zozzz
post Jul 16 2017, 01:48 PM
Post#3



Posts: 44
Joined: 29-January 15



Sorry Not Work My Friend
This post has been edited by zozzz: Jul 16 2017, 01:59 PM
Attached File(s)
Attached File  Default.zip ( 23.75K )Number of downloads: 3
 
Go to the top of the page
 
R. Hicks
post Jul 16 2017, 01:48 PM
Post#4


UA Forum Administrator
Posts: 40,460
Joined: 8-February 00
From: Birmingham, Alabama USA


What event are you using to execute the code ???
Also ... why even use code??
You can set the default value for the textbox within the properties of the specific textbox to do what you need ....

R.

--------------------
Ricky Hicks
Birmingham, Alabama USA
Go to the top of the page
 
zozzz
post Jul 16 2017, 02:03 PM
Post#5



Posts: 44
Joined: 29-January 15



hi sir.....
Please look to the Sample

You Are All Right But I Need this code for a reason. My Job in Technical office Unfortunately, I can't explain

i using

Private Sub Command4_Click()
Me.Text2.DefaultValue = """David"""
End Sub
This post has been edited by zozzz: Jul 16 2017, 02:18 PM
Go to the top of the page
 
R. Hicks
post Jul 16 2017, 02:57 PM
Post#6


UA Forum Administrator
Posts: 40,460
Joined: 8-February 00
From: Birmingham, Alabama USA


If you are using a command button to populate the string value .. you simply need to set the Value property to the desired value .. not the DefaultValue Property as you are tryting do.
So all you should need is the following code in the example below.

CODE
Private Sub Command4_Click()
Me.Text2 = "David"
End Sub

The value should be enclosed within double quotes as shown in the example above ...

R.

--------------------
Ricky Hicks
Birmingham, Alabama USA
Go to the top of the page
 
R. Hicks
post Jul 16 2017, 04:00 PM
Post#7


UA Forum Administrator
Posts: 40,460
Joined: 8-February 00
From: Birmingham, Alabama USA


After giving it some thought ...
If you are attempting to set the DefaultValue property of the textbox programmatically using VBA .. the try using the following example.

CODE
Me.Text2.DefaultValue = "='David'"


R.

--------------------
Ricky Hicks
Birmingham, Alabama USA
Go to the top of the page
 
tina t
post Jul 16 2017, 06:13 PM
Post#8



Posts: 5,051
Joined: 11-November 10
From: SoCal, USA


QUOTE
Private Sub Command4_Click()
Me.Text2.DefaultValue = """David"""
End Sub

to add to what Ricky said:

1) a control's Value property and its' DefaultValue property are two different things - they work differently, and are not interchangeable.

2) a control's DefaultValue is only assigned to new records, it has no effect when an existing record is edited.

3) a control's DefaultValue is only assigned when a new record is created - when the first keystroke "dirties" the record. if you set a control's DefaultValue property while the Current record in the form is an existing record, or a new record that is already dirty, the DefaultValue will not be assigned to the field bound to that control, in the Current record.

that may be a little hard to follow, if so, sorry - but i can't think of another way to explain it. my point here is that if you're using a command button to set the DefaultValue of a form control, it may be too late in the sequence of events. it all depends on the work process, and what you're trying to accomplish.

hth
tina

--------------------
"you can't take the sky from me"
Go to the top of the page
 
R. Hicks
post Jul 16 2017, 06:48 PM
Post#9


UA Forum Administrator
Posts: 40,460
Joined: 8-February 00
From: Birmingham, Alabama USA


Thanks for the additional information with your explanation of the two different properties.
I was wanting to attempt to explain that there was a difference between the two .. but was afraid I would create more confusion for the OP.
Your reply was very eloquent and "spot on".
..... keep up the great work that you do here at UA tina ... wink.gif

R.

--------------------
Ricky Hicks
Birmingham, Alabama USA
Go to the top of the page
 
zozzz
post Jul 16 2017, 11:23 PM
Post#10



Posts: 44
Joined: 29-January 15



set and save please

I mean when I close and open the form again "David" must be save
Go to the top of the page
 
theDBguy
post Jul 17 2017, 10:48 AM
Post#11


Access Wiki and Forums Moderator
Posts: 70,270
Joined: 19-June 07
From: SunnySandyEggo


Saved where? As a Value or as a Default Value? Those are two different things.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
tina t
post Jul 17 2017, 12:06 PM
Post#12



Posts: 5,051
Joined: 11-November 10
From: SoCal, USA


thanks, Ricky! :) but i think, from the op's subsequent post, and then DBguy's, that we're still not quite getting the point across... tina

--------------------
"you can't take the sky from me"
Go to the top of the page
 
zozzz
post Jul 17 2017, 11:44 PM
Post#13



Posts: 44
Joined: 29-January 15



Hi

saved as value please
Go to the top of the page
 
missinglinq
post Jul 18 2017, 11:12 AM
Post#14



Posts: 4,343
Joined: 11-November 02



You can only set the DefaultValue, in code, and have it last for more than the session you're setting it in (which is what it sounds like to me that you want to do) by doing so programmatically in Design View, something I've never tried, but perhaps someone else here has.

If this is being done in a multi-user environment, each user should have a copy of the Front End on their machine, and what I'd do is have utility Table in the Front End, and save the desired value to that Table, then retrieve it when the Form is opened.

Linq ;0)>

--------------------
Hope this helps!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
tina t
post Jul 18 2017, 11:12 AM
Post#15



Posts: 5,051
Joined: 11-November 10
From: SoCal, USA


QUOTE
saved as value please

then look at post #6. Ricky gave you the exact code you need.

hth
tina

--------------------
"you can't take the sky from me"
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    26th July 2017 - 03:31 AM