Need help with Docmd.OpenReport options

Romulus

Registered User.
Local time
Today, 07:41
Joined
May 21, 2001
Messages
30
I have the following code:

Private Sub Form_Current()
Dim ANS As Integer

ANS = MsgBox("Click on the button to generate a monthly report of followup items to be completed", vbOKOnly)
If ANS = 1 Then DoCmd.OpenReport "rptFollowups", acViewPreview, , "[IActToBeDt] = Date()"
End Sub

First of all, it is filtering on the current date for IActToBeDt, but the report comes up briefly only to be covered up by a form that is being opened at the same time (I want the form to come up and then the report to open up on top of that until the report is closed) and secondly, I am trying to make the filtering criteria an OR statement (i.e., if one date field is the current date OR another date field is the current date, list the appropriate records). Am I approaching this the wrong way? This report is based on a query, so I did try putting Date() in the criteria...or section of the query, which I thought would be the easier way and this did not work.

[This message has been edited by Romulus (edited 02-19-2002).]
 
1. You don't need to specifyDim ANS As Integer because

Dim ANS As Byte

is sufficient as an msgbox will return an value below 256. To assign an integer is just wasting memory.

2. I sit not better to open the form when the report closes because you do not want to use it until then anyway? If it is that you don't want it to show then put this in the OnOpen event of your report:

Forms("FORMNAME").Visible = False

and this in the OnClose

Forms("FORMNAME").Visible = True

to make the form visible again.

3.I think your filter should be:

"[IActToBeDt] = #"& Date()&"# OR "[OtherField] = #"& Date()&"#"

##'s surrounding values signify date fields

Alternatively, adding Date() to the query will also work, if you want to include two fields using an Either/Or you have to put Date() on separate lines of the query to tell the query to give you this OR that.
Putting Date() on the same line under two fields creates an AND statement.

HTH

Ian
 
Ian,

Thanks for the suggestions. I tried adding Date() to the query again as you suggested and it worked this time. I think the problem was that I used the criteria for the form and not the report - my mistake.

I left my code below the same except I changed Integer to Byte as recommended, and I got rid of the [IActToBeDt]....

I then tried using the visible property when opening and closing my report, but the report is still behind the form. What am I doing wrong? Is it not working because of my code below?
 
This behavior is usually caused when the PopUp property of the calling form is set to "Yes".

In the form's design view, click Properties, click the "Other" tab, and set the PopUp property to "No".

HTH,

Lyn
 
I went to the form properties and the pop-up option was already set to "no". I am still stuck.
 

Users who are viewing this thread

Back
Top Bottom