Reset Form

modest

Registered User.
Local time
Today, 04:49
Joined
Jan 4, 2005
Messages
1,220
Hey guys, take your time with this - i'm not in a hurry, it's just slipped my mind.

I'm reseting the form controls back to their default value. My code is as follows.

Code:
        For Each ctl In Me.Controls
            If ctl.Name Like "cbo*" Or ctl.Name Like "txt*" Then
                ctl.Value = ctl.DefaultValue
            End If
        Next ctl

The problem is the default value returns the literal string instead of the applied value. For instance if the default value was '=Null' then '=Null' is what you would actually see. I've tried ctl.requery but this does not work either.

Any suggestions?
 
my answer to that would be to just put some if statements in there...

like,
Code:
If InStr(ctl.DefaultValue, "Null") > 0 Then
    ctl.value = Null
ElseIf Right(ctl.DefaultValue,1) = "="  Then
    ctl.value = Right(ctl.DefaultValue, Len(ctl.DefaultValue) - 1)
End If
that code would say if the default value contains null, thenmake the value Null, else if the first character is "=" then the value is everything in the default value minus the first character.
 

Users who are viewing this thread

Back
Top Bottom