How do I prevent the first record from appearing on a form...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BobS
    New Member
    • Jul 2010
    • 10

    How do I prevent the first record from appearing on a form...

    I have written a form whose function is to delete the record I have entered under the search criteria. The user enters the asset tag in the text box and presses the search cmd box . The record is then displayed in the detail section and they can press the delete cmd box to delete the record. How do I prevent the first record in my database from appearing in the detail section when the form first comes up. I've tried a few things but nothing seems to work.

    Thanks,
  • dsatino
    Contributor
    • May 2010
    • 393

    #2
    The reason the first record is appearing is because you have the form bound to the underlying table. If you don't want to show anything on open, the best course is probably to unbind the form from the table. Then use some code to populate field values upon user input of the asset tag.

    You could also leave it bound and simply set the field visibilties to false on open and true on user input.

    There's probably several other ways as well, it just depends on what you're comfortable with

    Comment

    • Steven Kogan
      Recognized Expert New Member
      • Jul 2010
      • 107

      #3
      Dsatino is right.

      Opening a bound form without showing any records isn't well supported. You would end up taking a different approach.

      To go closer to your original method: If you remove the recordsource from the form and set each field control visible property to false you could use this sort of code for your search combo box.

      Code:
      Private Sub cboSearch_AfterUpdate()
          ' Find the record that matches the control.
          
          If Me.RecordSource = "" Then
              Me.RecordSource = "Test2"
              Me.ID.Visible = True
              Me.Field1.Visible = True
              
          End If
          
          
          Dim rs As Object
      
          Set rs = Me.Recordset.Clone
          rs.FindFirst "[ID] = " & Str(Nz(Me![cboSearch], 0))
          If Not rs.EOF Then Me.Bookmark = rs.Bookmark
      End Sub
      If the form has no recordsource but the fields are bound it displays "#Name".

      Comment

      Working...