-----Original Message-----
Hi Robert,
That makes things simpler.
You will still need a table that holds a boolean value (yes/no) to indicate
whether the fields have been cleared.
The basic logic would be:
1) if the date is anything other than the 15th, set the yes/no field to
false
2) check to if it is the 15th and if the yes/no field is false. this is because I'm
assuming the database could be opened and closed numerous times in one day and
this code will run in the open event on whichever form you choose. Once the
fields have been cleared, set the yes/no flag to true so it won't run again
on the 15th of the month.
So it would look something like this:
**air code**
Dim db As Database
Dim strSql As String
Set db = CurrentDb()
If Date() <> DateSerial(Year(Date()), Month(Date()), 15) Then
strSql = "Update yourNewTable Set yesnoField = 0"
db.Execute strSql, dbFailOnError
Else
If DLookup("[yesnoField]","yourNewTable") = 0 Then
strSql = "Update yourTable Set [field1] = Null, [field2] = null"
db.Execute strSql, dbFailOnError
strSql = "Update yourNewTable Set yesnoField = - 1"
db.Execute strSql, dbFailOnError
End If
End If
--
HTH
Dan Artuso, Access MVP
Hi Dan,
Sorry! Yes the database is used on a daily basis, to
update and revise records.
Thanks again
Robert
-----Original Message-----
Hi Robert,
It will clear whatever fields you put in the Update statement.
Again, is the database used on a daily basis?
If it's not, you will have to have some sort of indicator as to
whether the fields have been cleared for the specified interval.
The easiest would be to have a table with just one record, one field, that
contains a boolean value. So you'd end up with
something
like this:
If Date() > DateSerial(Year(Date()), Month(Date()),
15)
_
And DLookup("[yourField]","yourNewTable") = True Then
Dim db As Database
Dim strSql As String
strSql = "Update yourTable Set [field1] = Null, [field2] = null"
db.Execute strSql, dbFailOnError
strSql = "Update yourNewTable Set yourField = 0"
db.Execute strSql, dbFailOnError
Set db = Nothing
End If
--
HTH
Dan Artuso, Access MVP
Hi Dan,
Thanks for the tip, but will this clear select
fields
or
all fields of the table? Essentially what I need it
to
do
is clear just some of the fields after a specific date
say the 15th of each month, any help you can provide
would be greatly appreciated.
Thanking You again
Robert
-----Original Message-----
Hi,
Forms only display data from tables so you will
have
to
delete the data in the
relevant table. I'm going to assume that the db is used
on a daily basis, if it's not,
the date comparison will not work and you will need a
more elaborate method
to see if a month has gone by since the fields were last
cleared. The code below
will delete the data on the 1st of each month.
You can put this code in the form's Open event:
If DateSerial(Year(Date()), Month(Date()), 1) = Date()
Then
Dim db As Database
Dim strSql As String
strSql = "Update yourTable Set [field1] = Null,
[field2] = null"
db.Execute strSql, dbFailOnError
Set db = Nothing
End If
Substitute the correct names for yourTable and the
fields.
--
HTH
Dan Artuso, Access MVP
Hi, I'm trying to clear certain fields only in a form
so
that each month new info would need to be added without
having to delete all the info of each record.
Suggestions?
Thanks
Robert
.
.
.