Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a bound object as a label . . ?

Status
Not open for further replies.

OverDrive

IS-IT--Management
Dec 11, 2000
268
0
0
US
Is there any way to create a bound label?

Why I need this . . .
I have a form, and on this form I have a bound text box that has a default value of "0.325" which shows up on every new record. This rate (0.325) happens to be the monetary rate per mile for mileage for the year 2001 and is multiplied by the number of miles the client travels. Next year this number will change, so I would like to create a command button on the switchboard that will allow a person to change this rate every year?

Any Suggestions?

Chance~
 
Actually, I made a mistake, it dosent necessarily have to be a bound text. All I need to do is have a field (probably unbound) that I can change via another form that will show up on all my records. Just like a label, but it needs to be in a format that can be calculated (I know you can do this with a text box if there is a number in its field).

Hope you all understand all this mess . . . thanks

Chance~
 
just an idea:

1) why don't you have a disabled textbox with the default value set to 0.325.

2) then upon a button click you temporarily enable the textbox, so you can change it's value.

3) then in the after update event you update the default value (after the appropriate checks) set focus elsewhere & then disable the textbox again.

others may have better ideas but it's a start
 
I think I understand what you are saying, I tried it, and I think it may just be too much for a client to understand to be able to change it. It would be better if I could just get the darn thing to work like a label or something that will automatically show up on every new record. I have the default value set already to 0.325, now if there were just a way to change the default value via a command button or something . . . ??

Anyone?

Thanks for the help man . . .

Chance~
 
First, what you want to do is quite doable... something along the lines of

Private Sub MyButton_Click()
Me.MyMilageRateTextBox.DefaultValue = newValue
End Sub

But...
I've actually used an analogous process for default dates in timesheet entry. What I did was set up a text box in the header region of the form (not a tab stop). i used this text box to set up the default values of line item dates. it's a straightforward code to change the line item date defaults to the value entered up top.

Private Sub MyFromDateDefault_AfterUpdate()
Me.FromDate.DefaultValue = Me.MyFromDateDefault
End Sub

But I'm both the user & the programmer so things may not be user friendly enuf for your purposes.
 
Thanks man . . .

I took your advice . . .

Chance~
 
Wait a minute. You want your users to be able to change the default value, right? Giving them a command button to change the Default Value property will allow that, but it won't persist; the next time the form is opened, they'll be back to the 2001 value.

I'd suggest saving the default value in the registry. In your form's Load event, retrieve the value and plug it into the unbound text box's DefaultValue:
Me!txtMileageRate.DefaultValue = Val(GetSetting(AppName, SectionName, "MileageRate", "0.325"))
(AppName and SectionName are constants in your application that define the names of registry branches for your application. AppName should be some version of your application's name, and SectionName might be something like "UserPreferences".)

When your user changes the rate, you'll need to save it in the registry in the AfterUpdate event:
SaveSetting AppName, SectionName, "MileageRate", CStr(Me!txtMileageRate.Value)

Rick Sprague
 
Rick has way more experience so I listen when he posts.

But, Rick, I've been using A2K & doing this w/o saving the app settings as an extra step, in fact i have to go to pains to NOT have previous defaults settings set using the above method appear at "wrong" times.

Is this an A2K vs A97 kind of thing?
 
Rafe,

No, it's not a version dependency. I'm interpreting what OverDrive wants differently from you.

With your method, what is the source of the data in the form header? I assume it's not bound to the form's recordset. If it's unbound, you must either be typing in the value initially when you open the form, or there must be code that loads it from a Settings table or something like that. OverDrive said he wants it to act something like a label, so I'm assuming he wants a "set and forget" feature that will persist from one use of the form to another. Your method, if you use a Settings table, will persist, but if there are multiple users, they'll all share the same default value, and if somebody changes it, everyone else will be affected. My suggestion to use the registry avoids that; the setting applies only to the current user profile on the current machine.

You didn't mention using a table to hold your form header field's value, and I didn't think through your method enough to realize you probably were doing that, so the value will persist. But I still think the registry method supports multiple users better. Rick Sprague
 
OK, time to learn about setting registries.

& yes, now I see that my method changes with the "frontend copy" & not with "user profile."

thanks
 
Thanks for all the info. I too need to learn more on registry edits as well.

What I ended up doing is just creating an unbound drop down with the values being in another table.

On my switchboard I created a command button allowing the user(s) to change the value at any time they wanted. What this allowed was a way to add or change the values any time they wanted, but still had a bound object for calculation purposes.

I am sure your idea would work Rick, but you are way too advanced for me . . . thanks though (I need to learn more).

Thanks for all the help guys
Chance~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top