PDA

View Full Version : Solved: Default Value



RonNCmale
03-06-2011, 11:51 PM
Is there a way to have a message box to appear when you open up a database to select year that will enter the default value in the appropriate text box property field (default field). Example: Open database and a message box opens requiring user to input year. Once selected this value is placed in the text box (Year) in the default field (2011).

OBP
03-07-2011, 04:53 AM
I am not clear exactly what you want to do. Is the text box and default field on a form or in a table?
You can easily open a form and set the default value and have it overwritten by user input?
Is that what you need?

RonNCmale
03-07-2011, 05:56 AM
The text box is on a form. The user has to enter the year. I know how to open up the property and set the default value. I'm trying to make it user friendly where when the database is opened a message box would appear and have the user to enter the year, if a year had already been selected the message would not appear. Once selected this selected year would be set as the default value for the text box "year". So each record would have the year already selected and not have to be re-entered on each record. Hope this is a little clearer.

dicepackage
03-07-2011, 08:06 AM
I'm not sure if you are using forms or not but if so this is what I would recommend. I would set a variable called Year to be the variable that detects the year. I would then setup an Input Box to run on the form's startup by setting the Form Load Event Procedure. To have it auto-populate the field every time you change records you can set this in the Form_Current event procedure. You may want to do some null checking so you don't overwrite values accidentally such as replacing a 2010 record with 2011.


Dim Year as Integer

Private Sub Form_Load()
Year = InputBox("Enter the year", "Year Entry")
Me![YearTextBox] = Year
End Sub

Private Sub Form_Current()
Me![YearTextBox] = Year
End Sub

RonNCmale
03-07-2011, 04:59 PM
I have a Access database that has two text boxes. One is the Unit Number "3060" and the other is year 20 "11". I can open up the text box property and change the default value myself but I'm trying to make it user friendly where as when a database that has no records is opened a dialog box opens requiring the user to enter the Unit Number and the Year. once entered they will be set as the default value for each record corresponding with those fields. Once set as the default value, the dialog box will not open due to the fields have already been defined.

I've attached the database.

geekgirlau
03-07-2011, 07:54 PM
If the default lives only while the form is open, you will see a prompt every time the form is loaded - this will depend on how users interact with your database.

You could also have the default set for the period that the database is opened, which means that provided your user doesn't close the database, they'll only be prompted once each day.

There's also another way that you could set this:

Have a table containing the default values for these 2 fields (I usually have a "parameters" table to hold information like this)
The first time a user enters a value into one of those fields, ask if they want to set that as the default
If yes, update the value of the default field in your new table from Null to whatever they entered
This now becomes the default that you use for this session
Each time they enter a different value, ask again if they want to set this as the default
On exiting the database (or you could do it on launch) clear the 2 default fields in your new table

RonNCmale
03-07-2011, 10:26 PM
I think the second way would be more of what I have in mind. Could you upload an example or add to my database to see if this is what i'm looking for.

dicepackage
03-08-2011, 08:35 AM
I made the changes to your form's code. Give this a shot and see if this is what you are looking for. It prompts for the year at startup and then will automatically fill this in if the year is blank.

RonNCmale
03-08-2011, 10:16 AM
It is getting there. It ask for the year again when I close the database and again when I open it again. I wish for it to ask only once and then when the year is entered placed the year as the default value.

dicepackage
03-08-2011, 11:01 AM
The program does not have any ability to remember the variable year as it is coded currently. You could make a separate table and have the value stored there so that it saves. The downside of this is that it will not work with multiple users.

RonNCmale
03-08-2011, 02:40 PM
if you get time could you make the changes to have the year stored on a separate table using the grievance database and upload. If not thanks so much for your help.

dicepackage
03-09-2011, 02:21 PM
Well scratch that idea I said earlier. I tried it but it will not work the way your database is setup.

What I would maybe try to do instead is save this value in a text file. You could run a check so that if the text file is blank the program will then prompt for the date. From there you can store this value in the text value. Then when you want to retrieve it just run your code to get the date from the text file. You could also try a registry key but I like the text file idea better because it will work on a network drive.

RonNCmale
03-09-2011, 06:39 PM
Thanks dicepackage, I was just about to download the example when you made the new post. I'll see what I can come up with.

RonNCmale
03-26-2011, 12:14 AM
I've created a button on my database form field that will open another form that has three combo boxes. The first one picks the region, and the second one list the units in that region and the third shows the unit number. I now wish for the third combo box to place the unit number into the send to unit field. I've been working with it for weeks and can't seem to find a solution to populate the send to field from the combo box.

OBP
03-26-2011, 05:39 AM
Ron, before I look at your database does the user select the unit number in the last Combo?
If so add this to that combo's After Update event procedure
me.UnitField = me.combo(number goes here unless it has a name).Column(column number of Unit Number goes here)
Assuming UnitField is the name of your field.

OBP
03-26-2011, 05:42 AM
What is wron with what you have????

RonNCmale
03-26-2011, 07:34 AM
Nothing is wrong with it, I just wanted it to be a little user friendly. There are over 100 different units with different numbers and I wanted a way for the user to be able to input the Unit Number without having to look up the number or rely on memory. But thanks for looking at it OBP.

OBP
03-26-2011, 08:59 AM
Ron, that is what I don't understand, it is putting a number in?
Isn't that what you are talking about?

RonNCmale
03-27-2011, 09:54 AM
OBP, it was me, not understanding your answer, but after reading your post again and trial and error, I got it to push the number to the appropriated box. thanks OBP.