PDA

View Full Version : VBA to clear or reset text fields from a click of a command button



wedd
09-29-2011, 04:27 AM
Hi all, is it possible to add vba code to a command button that when clicked the event will clear existing data or reset data, so when the user is on the form, the previous data entered doesn't display? Is this possible, if so how can this be done? Also would you have any sample code on how to do this?


Thanks for your contributions :friends:

HiTechCoach
09-30-2011, 07:07 AM
Is the form bound or unbound?

Gurberly
09-30-2011, 07:19 AM
Hi

I use the below to set the edit mode on a form. You can adapt it to change it from setting thy back colour to setting the value/text... assuming form is not data bound

Dim ctl As Control
For Each ctl In Me.Controls
'109 = text box
'111 = cbo box
'106 = chkbox
Select Case ctl.ControlType
Case 109, 111
ctl.Locked = blnLocked
If blnLocked Then
ctl.BackColor = 8454143
Else
ctl.BackColor = 16777215
End If
Case 106 ' 106 does not have a back color
ctl.Locked = blnLocked
End Select
Next

...oops edit...blnLocked is just a variable passed in to flag whether locked or not.
G

wedd
09-30-2011, 07:22 AM
HiTechcoach, it is an unbound field.

HiTechCoach
09-30-2011, 03:26 PM
HiTechcoach, it is an unbound field.

I think you mean unbound control. Fields are in tales. Forms/reports do not have fields. They have controls. The Controls on a form/report can be bound to a field int the form/report's record source.

To clear a control use:

Me.ContriolName = Null