Full Version: how to use a button to delete value from field in table
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
cfcobalt
I am trying to have a button created that when it is cllicked on the form, three fields associated within the record source for that form are emptied or created as null, basically to override a previous value so that those fields in the form are empty.

How can I use a button to make three fields that are attached to a table through the form, empty? Can someone help pls.
Sligo
Welcome to UtterAccess!!!!!


If your table is bound to the form, and you are looking at the current record, what you need is pretty simple:

CODE
private sub cmdDelete_Click()

me.field1=null
me.field2=null
me.field3=null

end sub


This would have the same effect if the user entered the field and deleted the data.

There are a zillion variations to this that can be applied or considered. Here are a few:
1. Do you want to stop and ask the user "Are you sure?"
2. Is the data we're deleting NOT bound in our current form?
3. Are the target fields set to not allow nulls?

I hope this helps.

- Sligo
cfcobalt
thx. This will only delete the value in that record only for those fields and not all records for those fields in the table?
cfcobalt
when I did this, it said the following

'You Can't Assign a Value to this object'

this is what I put in the code of the button on the form

Private Sub cmdOverride_Click()

Dim stDocName As String

Me.strSig = Null
Me.strStmt = Null
Me.blnDone = False

stDocName = "frmStart"
DoCmd.Close
DoCmd.OpenForm stDocName

End Sub
cfcobalt
nevermind. I think I got it. thx again!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.