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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a fileds default value through code

Status
Not open for further replies.

Larsson

Programmer
Jan 31, 2002
140
SE
Hi!

I want to let the user change the default value for a filed from another form and I am using the following code:

Private Sub cmdOk_Click()
Forms![TelefoniImport_f]![cmdSnittTid].DefaultValue = Me.cmdSnittTid.Value
Forms![TelefoniImport_f]![cmdSnittTid].Value = Me.cmdSnittTid.Value
DoCmd.Close
End Sub

The problem is that when I check properties and default value for cmdSnittTid, then it is the same as before the change.

But when I run debug and checking the default value there it is correct.

So what do I do wrong?

Thanks for all help. Markus Larsson
 
The problem is that when you set form or control properties from VB, its like setting a variable. It is in effect for as long as that instance of the form or control is valid, but isn't saved with the form.

I did a little playing trying to save the form from code and wasn't successful in saving the DefaultValue so it was valid the next time the form was opened. Sorry, but maybe this will point you in the right direction.

Unless someone has a better solution, you may need to save your default value to a table then look it up and reset it every time the form is opened. Unelegant and brutish as it seems, I don't have a better solution. I hope someone else does because now I'm curious. Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
 
That was what I suspected. I didn'r want to use a table, it is so much work with that, but it seems like I don't have a choise.

Markus Larsson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top