display form on a specific date

B

bjwheeler

Hi There,

I want to display a form only on the 15th day of every month.

Having looked a other forums around the place, i have tried a couple
of solutions however, they do not work... e.g

Private Sub Form_Open(Cancel As Integer)
Dim dte As Date

'Check to see if today's date is 15 of any month
dte = Format(Date, "DD/MM/YYYY")
If Left(dte, 5) = "15/01" Or "15/02" Or "15/03" Or "15/04" Or "15/05"
Or "15/06" Or "15/07" Or "15/08" Or "15/09" Or "15/10" Or "15/11" Or
"15/12" Then
'Turn off system warnings
DoCmd.SetWarnings False
DoCmd.OpenForm "CompactReminder"

End If
End Sub

Can someone please assist.

cheers

BW
 
M

Mr B

I assume that your code is opening a form and at that point, if the current
day is the 15th then you want another form to be opened.

Try the following:

dim bytDay as Byte

bytDay = Day(Date)

If bytDay = 15 then
DoCmd.OpenForm "CompactReminder"
End If
 
T

Tom van Stiphout

On Tue, 30 Sep 2008 23:47:16 -0700 (PDT), (e-mail address removed) wrote:

You already got a good answer using the Day function. To explain why
your code does not work, consider this simpler example:
Dim x As Integer
If x = 1 Or 2 Then
MsgBox "Yes"
End If

This code doesn't work as you might expect, and should be rewritten
as:
If x = 1 Or x = 2 Then

The original line will be interpreted by VBA as:
If (x = 1) Or 2 Then
so this first evaluates the boolean expression (x=1) which can be true
or false depending on the value of x prior to this line of code, and
then invokes the bitwise Or operator - not what you meant to do.

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top