Run Command On Certain Date

  • Thread starter Thread starter PaleRider
  • Start date Start date
P

PaleRider

Hi,

I want to be able to show a popup message once every 14 days. How do I code
this in VB. Thanks in advance.

PR
 
Hard to be specific without knowing more about the circumstances
in which you want this message box to appear (when the db opens,
when a form opens, when something else happens?), but generally
speaking you could have a simple table with one date field. In an
event procedure you could check this date against the current date
using DateDiff, and if it's been 14 days pop a message box and
reset the table value to the current date.

Alternatively, you might be able to use a global variable for the
same purpose.
 
Hi,

I want to be able to show a popup message once every 14 days.  How do Icode
this in VB.  Thanks in advance.

PR

create a custom property of type Date.
then use these routines to Get and Set the date...

If you create a popup form to handle this, you could set the value in
the Close event of the form.


Option Explicit


'-----------Start Code Block-----------
Function SetCustomProperty(strPropName As String, intPropType _
As Integer, strPropValue As String) As Integer

Dim dbs As Database, cnt As Container
Dim Doc As Document, prp As Property
Const conPropertyNotFound = 3270 ' Property not found error.

Set dbs = CurrentDb ' Define Database object.
Set cnt = dbs.Containers!Databases ' Define Container object.
Set Doc = cnt.Documents!UserDefined ' Define Document object.
On Error GoTo SetCustom_Err
Doc.Properties.Refresh
' Set custom property name. If error occurs here it means
' property doesn't exist and needs to be created and appended

' to Properties collection of Document object.
If strPropName = "" Then GoTo SetCustom_Bye Else
Set prp = Doc.Properties(strPropName)
prp = strPropValue ' Set custom property value.
SetCustomProperty = True

SetCustom_Bye:
Exit Function

SetCustom_Err:
If Err = conPropertyNotFound Then
Set prp = Doc.CreateProperty(strPropName, intPropType,
strPropValue)
Doc.Properties.Append prp ' Append to collection.
Resume Next
Else ' Unknown error.
SetCustomProperty = False

Resume SetCustom_Bye
End If
End Function

Function GetCustomProperty(strPropName As String) As String
Dim dbs As Database, cnt As Container
Dim Doc As Document, prp As Property

' Property not found error.
Const conPropertyNotFound = 3270

On Error GoTo GetCustomProperty_Err
Set dbs = CurrentDb
Set cnt = dbs.Containers!Databases
Set Doc = cnt.Documents!UserDefined
Doc.Properties.Refresh
GetCustomProperty = Doc.Properties(strPropName)

GetCustomProperty_Bye:
Exit Function

GetCustomProperty_Err:
If Err = conPropertyNotFound Then
Set prp = Doc.CreateProperty(strPropName, dbText, "None")
' Append to collection.
Doc.Properties.Append prp
Resume
Else
' Unknown error.
GetCustomProperty = ""
Resume GetCustomProperty_Bye
End If
End Function

'-----------End Code Block-----------
 
Beetle,

I want the procedure in the OnOpen or OnLoad part of the form, whichever
happens first. This global variable thing, how would that work and how do I
set it up. If that way is easier to do then I would prefer that way,
otherwise I could put a date field in my table and work off that. What do
you recommend?

PR
 
Back
Top