Setting default values for fields using button

bigalpha

Registered User.
Local time
Today, 11:33
Joined
Jun 22, 2012
Messages
415
I have a blank form that is usually entered from scratch, so all the fields are empty.

We do fill out the form with standard data occasionally, so I'd like to be able to assign a button or use a combo box to automatically fill those fields with predetermined data.

Two questions:
1) Can I use a 'on click' for a button to populate the data using this:
Code:
Me.Control1.DefaultValue = Chr(34) & Me.Control1 & Chr(34)
2) If I have a default value fill a combo box, will it save the bound column correctly since I didn't select it from the drop down itself?
 
You could have a text box bound to a field in the forms Record Source (table/query) and have a combo box with some code in its After Update event that sets the value of the text box to the value of the selection in the combo box.
 
So I could set a query as the record source for the combo box, and set the text boxes equal to each column of the combo box?
 
So I could set a query as the record source for the combo box, and set the text boxes equal to each column of the combo box?
I think you could. Give it a try and let us know if you have any problems.
 
BigAlpha,

Two answers:
1) Almost.
2) Yes.

Instead of changing the Default Value, I'd prefer to go with the Value property. And what is the value you want to populate the field with? Certainly it's not going to be Chr(34) & Me.Control1 & Chr(34), is it? That would take the value of Control1 and just put quotes around it. I don't think that's what you want. Let's say the value you want to put in that control is "Normal", then your pushbutton code would be this:
Code:
Me.Control1.Value = "Normal"

And yes, if you change the value of a bound combo box programmatically, the value will be saved in the source table just as if it were selected with a mouse click.

Coming back to the first question... If you do change the .DefaultValue property, you wouldn't have to click the button for each record. This could have some value. Say for example, you are entering records and you see that the next hundred records are in "CA", you could set the Default Value for the State control to "CA" and then skip that field until you finish the CA records. Then your next group is in "CO" so you can enter CO in the State control, click your 'Change Defaults' button, and work through that group. I think you are on to something. If THAT is what you meant to do, then YES, you can do that. It should work. Please let us know.

Thanks!
_________________
Regards,
Marvin M :cool:
Windows 7 Professional, MS Access 2007/2010
Windows 8 Professional, MS Access 2013
-------------------------------------------------------------------------------------------------------------------
If my post has helped you, please click the scales or click the 'Thumbs up'. Thanks!
-------------------------------------------------------------------------------------------------------------------
 
Thanks for the reply. That snippet I used is something I found somewhere else. also, I think you're right about using .value instead.

I guess setting a value as default is the wrong terminology, since I don't want it to always be default. I just wanted something that I could populate my form with sometimes. Haven't had a chance to implement yet, though.
 
Yeah, but the more I thought about it, the more I thought, "That's really not a bad idea." I know, from working with data entry, that sometimes you repeat the same data in the same fields over and over again. You get tired of typing "Los Angeles" a hundred times without a typo. There's the copy and paste trick, but that is only good for one field. If there are five or six fields on my form that may be subject to repetition through many records at a time, this change default idea of yours could be a real time saver. I'll have to discuss with the users about what term would make sense for them on that button caption. But I'll keep this idea in my skull bucket until I find a good place to use it.

Thanks!
Marvin M
:cool:
 

Users who are viewing this thread

Back
Top Bottom