Results 1 to 4 of 4

Thread: Clearing Forms

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Unanswered: Clearing Forms

    Hi guys,
    I am using a form which has a combo box and text boxes. When I open the form, I want it to be clear. I tried to set the deafult values to "" and it didn't work.
    I even tried to set a new records

    Private Sub Form_Load()
    Call ClearHistory
    Me.txtFullName.SetFocus

    End Sub
    Private Function ClearHistory()
    DoCmd.GoToRecord , , acNewRec
    End Function

    But I get the following error: runtime rroe '2110':
    Ms Access can't move the focus to control cmbTAGIDfilter.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You could try:
    Code:
    Dim ctl as Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox then ctl.Value = Null
    Next
    Be careful, though because in doing so you actually modify the data if the controls are bound to a data source.
    You can also use:
    Code:
    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Then
            ctl.SetFocus
            ctl.Text = ""
        End If
    Next
    But this requires that the controls are not locked or disabled.
    Have a nice day!

  3. #3
    Join Date
    Apr 2010
    Posts
    5
    Hi guys,
    I need to compact and repair my database 2007 using VBA code, how can I do that?

    Thanks,
    Behi

  4. #4
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by bseyedes View Post
    Hi guys,
    I need to compact and repair my database 2007 using VBA code, how can I do that?

    Thanks,
    Behi
    Behi,

    see my reply here
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    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
  •