reset command not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jinalpatel
    New Member
    • Mar 2008
    • 68

    #1

    reset command not working

    I am totally new to the VBA and I have following problem.
    I have two tables
    Holderdata : Parent ; Purchasedata : child
    I created a search form based on holder data. the search criteria (User input) is "Lastname". I want to show the search results based on lastname from holder data in mainform and relative purchasedata from purchasedata to the subform.
    I have to commands called search and resetsearch. Search is working. For resetsearch I want to clear the "searchbylastna me" textbox as well as all the fields on mainfrom and subform.
    Here is all my code
    Please help!!
    [CODE=vb]
    Dim strsql As String
    Dim strlname As String
    Dim strwhere As String
    Dim lnglen As Long
    Private Sub form_load()

    Me.filter = "(False)"
    Me.FilterOn = True

    End Sub


    Private Sub cmdsearch_Click ()

    subfrmsearchbyl name.Locked = True
    txtfirstname.Lo cked = True
    txtlastname.Loc ked = True
    txtmi.Locked = True
    txtaddress.Lock ed = True
    txtaddress2.Loc ked = True
    txtzipcode.Lock ed = True
    txtcity.Locked = True
    txtstate.Locked = True
    txttelephone.Lo cked = True
    txtbdate.Locked = True
    txtdeceased.Loc ked = True
    txtheight.Locke d = True
    txtweight.Locke d = True
    txtheducation.L ocked = True
    txteyecolor.Loc ked = True
    txthaircolor.Lo cked = True
    txtcstate.Locke d = True
    txtsex.Locked = True
    txtfirstname.En abled = False

    If Not IsNull(Me.txten terlname) Then
    strwhere = strwhere & "([LAST_NAME] = """ & Me.txtenterlnam e & """) And "
    End If

    lnglen = Len(strwhere) - 5
    If lnglen <= 0 Then
    MsgBox "Nothing is specified", vbInformation, "Nothing to Show"
    Else
    strwhere = Left$(strwhere, lnglen)
    Me.filter = strwhere
    Me.FilterOn = True
    End If
    End Sub
    Private Sub cmdReset_Click( )
    'Purpose: Clear all the search boxes and show all records again.
    Dim ctl As Control
    'Clear all the controls in the Form
    For Each ctl In Me.Controls

    Select Case ctl.ControlType
    Case acTextBox
    ctl.Enabled = False

    End Select
    Next

    'Remove the form's filter.
    Me.FilterOn = False
    End Sub[/CODE]
    Last edited by Scott Price; Mar 27 '08, 02:55 PM. Reason: code tags
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    On line #57 of your code you need to do more than just Disable the control! To reset you will need to add on the next line:

    Code:
    ctl.Value = Null
    Please remember to use the [CODE] tags provided in future, especially when posting large blocks of code! They are simple to use: just select your code text and click on the # icon on the top of the reply window. Doing this makes your code MUCH more readable, and, as a result, your question much more likely to get an answer! Thanks and welcome to the Scripts!

    Regards,
    Scott

    Comment

    • jinalpatel
      New Member
      • Mar 2008
      • 68

      #3
      Thanks Scott.
      But I have date field, which shows the data after I click the Reset button. Is there anyway I can show Empty filed for the date field as well subform(which shows the purchase data of a holder)

      Thanks for help
      Code:
      Private Sub cmdReset_Click()
          'Purpose:   Clear all the search boxes and show all records again.
          Dim ctl As Control
          'Clear all the controls in the Form
          For Each ctl In Me.Section(acHeader).Controls
      
              Select Case ctl.ControlType
              Case acTextBox
                  ctl.Value = Null
              End Select
          Next
      
          'Remove the form's filter.
          Me.FilterOn = False
      End Sub

      Originally posted by Scott Price
      On line #57 of your code you need to do more than just Disable the control! To reset you will need to add on the next line:

      Code:
      ctl.Value = Null
      Please remember to use the [CODE] tags provided in future, especially when posting large blocks of code! They are simple to use: just select your code text and click on the # icon on the top of the reply window. Doing this makes your code MUCH more readable, and, as a result, your question much more likely to get an answer! Thanks and welcome to the Scripts!

      Regards,
      Scott

      Comment

      • Scott Price
        Recognized Expert Top Contributor
        • Jul 2007
        • 1384

        #4
        Originally posted by jinalpatel
        Thanks Scott.
        But I have date field, which shows the data after I click the Reset button. Is there anyway I can show Empty filed for the date field as well subform(which shows the purchase data of a holder)
        A little clearer wording please! Do you mean that the date field you want to clear is located on a subform?

        Regards,
        Scott

        Comment

        • jinalpatel
          New Member
          • Mar 2008
          • 68

          #5
          No.
          I have a Main form(bound to holder data) which contain a subform(purchas e data). On mainform there is a "Date of Birth" field.
          Also, Mainform heade section contains "LastName - Search" field
          Now I want following:
          When I click on Reset button, Every field on Mainform (header and detail) and subform datagrid should clear the values.
          Nothing should be dispalyed...Eve ry textfileds should be clear.

          I hope this helps...

          Originally posted by Scott Price
          A little clearer wording please! Do you mean that the date field you want to clear is located on a subform?

          Regards,
          Scott

          Comment

          Working...