Default Value from previous entry into field

jmriddic

Registered User.
Local time
Today, 20:16
Joined
Sep 18, 2001
Messages
150
Hi,

I have a user who would like the value from the last entry into the form's title field text box to show as the default value when he clicks on enter new issue button to bring up a new record. I do not know if this is possible but I thought I would check for him.
 
Yeah, you can set the default value by using:

Me.YourControlNameHere.DefaultValue = Me.YourControlNameHere

In the form's Before Update Event.

if you want to keep it changed when you reopen the database, you will have to either store the value in a table and load it at runtime or make the form go into design view and then set it and save the form, which is not so elegant.
 
I get this when I put the code in

This is what I get in the field :

#Name?
 
Make sure the field name and the control name are not named the same.
 
here is what I have

here is the code I have:

Me.Title.DefaultValue = Me.Title

The name of the textbox is Title but the Control Source is Event Name
 
I have attached a screenshot

Its in the VBA code window
 

Attachments

Okay, got it for you. In the Form's Before Update event use this:

Code:
    Me.txtTitle.DefaultValue = Chr(34) & Me.txtTitle & Chr(34)
 
Hi Bob

That seem to work. I think the user is going to probably is going to want what is on the previous record in the event name to show up the first time they go to the new issue blank record. Right now I have to enter something the first time for it to show on the second blank record. Is there a way to do that? I think the article I referenced try to address that but I couldn't get it to work right.
 
What I would do is to create a table to store that info. Then, in the form's Unload event, use an Update query to store the value to the table and then in the form's Load event use a DLookup to pull the value from the table.
 
I am very rusty

I have not done access work here for a while so I am ruther rusty on the syntax. Can you give me the general syntax for both parts? It would be much appreciated.
 
Okay, I just did it within your db you sent. See if you can figure it out. I added Load and Unload event code, a tblPreferences table, and an update query to update the table.
 

Attachments

I follow it somewhat

What does nz mean in the lookup and what is the purpose of the three fields in the table. Thanks for the help.
 
NZ is a function that handles null values if found. So that way you don't get an error.

The three fields:

1. the ID field - Primary key (I always have one)
2. The Preference Name - the name of the preference, which means you can use this table for storing any other preferences as well.
3. The preferences value - what the value of the preference is.

Does that help?
 
Thanks for the info

Yes that helps alot. I am so rusty on this as I have other areas of responsbility here at work and this is the first time I have dealt with access question in probably close to a year. I will have to find some tutorials and refresh myself.
 

Users who are viewing this thread

Back
Top Bottom