Default Values for a Form

timothyd

Registered User.
Local time
Today, 12:20
Joined
Feb 9, 2010
Messages
41
I creating a form that will require a lot of repetitive data to be entered in. I was wondering if there is a way to set up a default button on the bottom of the form that will set the default values for any field that contains a value when pushed. That way, the values can change from time to time with ease as the default values need to be changed. This is important since I will not be the one maintaining the database and thus cannot go in and change the default values anytime I want.

Thanks in advance.
 
I thought if you right click on the text box in the form design view and then go to properties, click on the data tab and about 4 boxes down is "default value"

That may work?

Alternatively if you have several possible default values you could use a list box for alternatives AND still designate a default value to be highlighted. I do this in the table design view though by changing display control in the look up tab to List box and the row source type to value list.
 
I would start with a drop down box with the different defaults. Example A, B and C

Then do an if statement, something like this.

If me.dropdown = "A" then
me.default_Field1 = "Blah"
me.default_Field2 = "Blah Blah"
me.default_Field3 = "Blah Blah blah"

if me.dropdown = "b" then
me.default_Field1 = "Blah"
me.default_Field2 = "Blah Blah"
me.default_Field3 = "Blah Blah blah"

else

me.default_Field1 = "Blah"
me.default_Field2 = "Blah Blah"
me.default_Field3 = "Blah Blah blah"

Does this make sense?
 
What you are suggesting is a bit complex. A good starting point would be Allen Browne's article here: http://www.allenbrowne.com/ser-24.html. That should at least tell you how big this is (pretty big).

If you decide to tackle it (i.e. the above functionality isn't enough), you'll need unbound controls to parrot the controls you want to "duplicate". You'll probably want to keep those controls in the form's header or footer. Another method would be to keep the default values in a template table.

At any rate, you'll probably want a button to save the current record as the template and another button to "import" the template into the current record (unless you utilize Allen's event code for that).

This sounds like a fun project but a lot of work. Will you post your results here when you've finished it?
 
Thanks for the help.

The reason why I can't use a drop down box is because I have no idea what the values will be when entered, such as the city in which the user's clients are located. Instead of always having to enter in the same city every time, it would be nice to have it defaulted to this. I also don't know where this product will end up and may move occasionally so it would be nice to change that value easily. I know this may be difficult but if it can be done, it would be a very nice feature.

If I can get it to work, I will post the results.
 
If your form is bound to a underlying table, then you can save the default values of your fields in the table structure, so every new entry will use the default value for those fileds in your new entry.

How's that?

Khalid
 
You can have an "Add" button to add a new blank record. Then you can have an "Add with Defaults" button, same code as Add button, but after adding the blank record, fill in defaults for the fields you want.

Or you can have a "Clone" button which copies certain fields from the current record, and copies the values to a new record. Useful if many students share the same address/household.

Here is the code for cloning. Put in the Click event.
Code:
' This seems to work. It clones the record, then goes to the new record.
On Error GoTo Err_cmdClone4_Click
Dim tstr As String, procname as string

procname = "cmdClone"

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend

'DoCmd.GoToControl "txtDate" ' Go to specific control, optional.

tstr = "You are viewing the new record now."
MsgBox tstr

Exit_cmdClone4_Click:
Exit Sub

Err_cmdClone4_Click:
Call DispError(procname)
Resume Exit_cmdClone4_Click
 
I really like the idea of a clone, but let me take it one step further.

I propose the idea of a default table that contains all the same fields as the form and when the "default button" is pressed, the current values are stored in the table. Then when a new record comes up, it loads the values from the default table into the form.

I am not very good at coding macros or code yet but do any of you think this is a plausible idea? If so, could you please help me with the code? Thanks!
 
I propose the idea of a default table that contains all the same fields as the form and when the "default button" is pressed, the current values are stored in the table. Then when a new record comes up, it loads the values from the default table into the form.

I personally prefer this technique to get my form populated with the default field’s data. This reduces my lot of code writing in VBA.

Hope this solve your problem:
Cheers
 

Users who are viewing this thread

Back
Top Bottom