Consulting

Results 1 to 5 of 5

Thread: VBA to clear or reset text fields from a click of a command button

  1. #1
    VBAX Mentor
    Joined
    Aug 2010
    Posts
    457
    Location

    VBA to clear or reset text fields from a click of a command button

    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

  2. #2
    Is the form bound or unbound?
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    3
    Location
    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

    [vba]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[/vba]

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

  4. #4
    VBAX Mentor
    Joined
    Aug 2010
    Posts
    457
    Location
    HiTechcoach, it is an unbound field.

  5. #5
    Quote Originally Posted by wedd
    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
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •