How to Edit or manipulate tables using a button in the GUI (code issue)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Clubsandwich
    New Member
    • Sep 2010
    • 3

    How to Edit or manipulate tables using a button in the GUI (code issue)

    I'm trying to create a button on my GUI that will access a table or query I have created elsewhere and change all of the values of one field to "off".
    I use this application to create reports based on the options I select but need to reset them occasionally with out resetting the whole form to its original state.

    The only code I have tried so far is;

    Code:
        For Each Value In Table.Table1.Selected
            Set Value = Null
        Next
    and this hasn't worked, I'm showing you just so you can get a better idea of what I'm trying to accomplish.

    Thanks
  • gnawoncents
    New Member
    • May 2010
    • 214

    #2
    It might be easiest to create an update query to set the field to "off" and then run the query when you press the button.

    Comment

    • Clubsandwich
      New Member
      • Sep 2010
      • 3

      #3
      So this update query will be able to reset a field in a different query/field?

      Comment

      • Mariostg
        Contributor
        • Sep 2010
        • 332

        #4
        Yes.
        The generic form is
        Code:
        UPDATE tableName SET fieldName='off' WHERE fieldName='on'
        This would set to off all values that are on in field fiendName

        Comment

        • Clubsandwich
          New Member
          • Sep 2010
          • 3

          #5
          I like the sounds of this but I'm still confused about some logistics.
          Where would I use the code you provided?
          How do I create an "update query" and link that to happen when a button is pressed?
          I'm fairly new to access...

          Comment

          • gnawoncents
            New Member
            • May 2010
            • 214

            #6
            It can be done in embedded SQL or by creating a query object (perhaps the easiest way if you're just starting).

            Start by creating a regular query and select the table/item to modify.

            Click the button to change it to an update query.

            Add the data you want updated in the "Update To" area and add any criteria in the "Criteria" field.

            Save the query and note the name.

            You can run the query from a button. The easiest way to set this up is use the button wizard, select the Misc. category and then "Run Query" from Actions. Then select the query you just created. When you press the button it will run the query. If needed, you can remove the warnings with the setwarnings = false, then turn them back on with true later.

            Comment

            Working...