Note: Run this in debug mode to trap the specific error message for controls which do not have a default property like labels, etc. Call the subroutine like so, passing it the Me.Form as a parameter so that it can spin through the collection of controls on the form and reset them to their default value if they have one. This is off the top of my head at work, so there may be some slight syntactical errors but this should do the trick for you.
ResetToDefaults Me.Form <== Call the sub this way in code
Good Luck!
Sub ResetToDefaults(ByRef rfrmMe As Form)
Dim ctl As Control
On Error GoTo Err_ResetToDefaults
For Each ctl In rfrmMe.Controls
Debug.Print ctl.Value, ctl.Default
ctl = ctl.Default
Debug.Print ctl.Value, ctl.Default
Next
Exit_ResetToDefaults:
Exit Sub
Err_ResetToDefaults:
Select Case Err.
Case whatever
REM Do nothing
Resume Next
Case Else
MsgBox Err.Description & " " & Err.Number
Resume Exit_ResetToDefaults
End Select
End Sub
A Buckeye in Irish country...must be scary. I'm sitting in sunny Columbus, OH myself right now. Thanks for the code. I will try and implement this, and let you know if I can get it to work...a dicey prospect considering my abilities....
If you post an email, I will be happy to send you working code from home. My email address is in my profile. If you don't have a programming background, give some more detail about what you are trying to do as the above code could be called from several places depending upon your answer.
Basically, everything in Access is a collection of something, and a form has a collection of controls associated with it. The above code just spins through all of the controls on the form resetting the value for you.
The for each is just a special case of a for i = 1 to x next loop specifically for containers. Kind of like, for each empty cupcake wrapper, fill with batter for baking.
Yes, it gets lonely out here. But, when someone gives me too hard of a time, I just ask them for the score to the 95 game, or if that is too painful, the 96 game. My desktop wallpaper is Eddie George running away from a whole posse of Domers .
A slight style point, indent the ctl=ctl.default piece as you have the others.
Because you pass the form object into the procedure as a parameter, you can drop this code anywhere you want to on other forms and it will work without changes.
Good Luck!
PS. Keep me in mind for excess Buckeye football tickets.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.