Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009

    Unanswered: Error when clearing form

    Hi guys

    Using access 2007

    Basically i have created a form (Majority unbound) and wanted the user to be able to save the form (done) and then clear the form in order to input the new data.

    I already have a clear button that clears a majority of the controls on the form using this VBA code

    Private Sub Clear_form_Click()
    Dim ctl As Control

    On Error Resume Next

    For Each ctl In Me.Controls
    ctl.Value = ctl.DefaultValue

    Set ctl = Nothing

    End Sub

    This is all well except one point :

    The last text box doesn't clear, instead it says #Error. The Text box is simple i just created it from the MS ribbon and entered the name of it and a simple calculation which is : =[Quantity]-[Quantity_out].

    this obviously means that not all the controls are clear and new so How exactly do i over come this??

    Anything else i can do please ask


  2. #2
    Join Date
    Dec 2004
    Madison, WI
    Yes. You're getting an error because once you cleared the fields, it no longer sees 'any' values in your formula. Instead of 'clearing' the values for Quantity, Quantity-out, you may want to set these to 0. Either that or add some testing in your calculation formula to test for null values.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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