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

resetting controls to their default value

Status
Not open for further replies.

ProgramError

Programmer
Mar 2, 2005
1,027
0
0
GB
Trying to rest all controls on a form with unbound controls back to their default values. Any help would be appreciated.

Code:
 For Each ctrl In Frm  '.Controls
  Debug.Print ctrl.Name
  
    If ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox Then
      ctrl.Value = ctrl.DefaultValue
    End If
  Next


Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Howdy ProgramError . . .
Code:
[blue]For Each ctrl in [purple][b]Me.Controls[/b][/purple][/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
sorry TheAceman1 I may have misled you with the commented out .comments statement which I left in by mistake.

I have no problem looking at each control and determining if they are a text box or combo box, which this routine does.
My problem is to clear out all text and combo boxes and put their default values in them.

The reason for doing this is when the form controls are bound to fields in a table, the user sometimes gets a message that the text or combo box 'cannot be updated at this moment' so cancels the error message box and retypes the information in this second time without a problem. This is happening too often and is slowing work down so I thought an unbound form approach may be the solution.
the addition and edit properties on the form are true and the form in its bound form use to goto a new record each time.



I have thought about storing all the default values in a table and putting them back into the controls after saving.

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
ProgramError . . .

Why not use the [blue]Tag[/blue] property of the controls to store the defaults!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
What is not working? The code looks fine. I can get it to work, but maybe I do not have the same conditions. I double checked with bound and unbound controls.
 
The error returned is 'You can assign a value to this object'
which occurs when the subroutine is called from the on load event.
I have tried it after the form has loaded and it works!!!
What I assume is happening, the controls are not available to update whilst the form is loading. Only afterwards can they be altered.

All I need to do now is decide in which event to put the routine.

Thanks

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Just a guess: use the Load event instead of the Open event.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, it was the load event I as using
but I will try the open event.

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
still the same error.

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Will work fine on Load if you don't set the ControlSource for the controls you want to change the .Value property for...

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top