Delete Field Content - Using Query or code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pmc1

    #1

    Delete Field Content - Using Query or code

    Hi,

    I have a table (tblResults) that was created uning a make table query.
    I will be using the table to export the results of the query to a csv
    file.

    Every field in the first 2 columns of the table (tblResults) is
    populated as expected but now I want to automate removing any data from
    these 2 columns below the first row while leaving the data in columns 3
    -10 untouched.

    How can I automate the removal of the contents of specific fields in a
    table using a query or through code.

    Thanks in advance


    Paul

  • Rich P

    #2
    Re: Delete Field Content - Using Query or code

    Hi Paul,

    To remove data from columns in a table but still retain the rows would
    be a Table Update. With Sql you can Delete Rows Insert Rows, and Update
    rows. These are the three basic action queries.

    In your scenario, to update your table you need to be able to identify
    the row that you don't want to update. Lets say you have an ID field
    and you know what that ID is. Then you can write a sql statement like
    this:

    Private Sub Button1_Click(. ..)
    DoCmd.RunSql "Update tbl1 Set fld1 = '', fld2 = '' + _
    & "Where RecordID <1"
    End Sub

    This will clear fld1 and fld2 for all rows in your table excpet the row
    where the RecordID = 1.

    HTH

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • pmc1

      #3
      Re: Delete Field Content - Using Query or code

      Hi Rich,

      Thanks a million! That worked a treat.

      Cheers

      Paul

      Rich P wrote:
      Hi Paul,
      >
      To remove data from columns in a table but still retain the rows would
      be a Table Update. With Sql you can Delete Rows Insert Rows, and Update
      rows. These are the three basic action queries.
      >
      In your scenario, to update your table you need to be able to identify
      the row that you don't want to update. Lets say you have an ID field
      and you know what that ID is. Then you can write a sql statement like
      this:
      >
      Private Sub Button1_Click(. ..)
      DoCmd.RunSql "Update tbl1 Set fld1 = '', fld2 = '' + _
      & "Where RecordID <1"
      End Sub
      >
      This will clear fld1 and fld2 for all rows in your table excpet the row
      where the RecordID = 1.
      >
      HTH
      >
      Rich
      >
      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      Working...