Solved

Need Between.. And to work with criteria from dialog box

Posted on 2008-10-10
4
288 Views
Last Modified: 2012-05-05
I am putting together a report that will list calls received for a one week period.  I created a dialog box so that the user can input the start date.  In my query in the DATE field I tried to put the following criteria, but its not working.

Between [Forms]![frmWklyDialog]![StartDate] And [Forms]![frmWklyDialog]![StartDate]+7

I need it to pull records dated between whatever they enter in for the start date and the start date plus seven days.

Thanks
0
Comment
Question by:MissB618
4 Comments
 
LVL 7

Expert Comment

by:rheitzman
ID: 22691339
You can use a Where clause on the OpenReport method. The sample below adds one month. You can use "ww" for a week or "d" for days. See help for DateAdd().
Private Sub Command0_Click()

On Error GoTo Err_Command0_Click

    Dim stDocName As String

    Dim stWhere As String
 

    stDocName = "Report1"

    stWhere = "Last_Update_Date BETWEEN #" & Me.txtStartDate _

        & "# AND #" & DateAdd("m", 1, Me.txtStartDate) & "#"

    DoCmd.OpenReport stDocName, acPreview, , stWhere
 

Exit_Command0_Click:

    Exit Sub
 

Err_Command0_Click:

    MsgBox err.Description

    Resume Exit_Command0_Click

End Sub

Open in new window

0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 22691518
if your ( DATE field ) is DateTime data type

Between cdate([Forms]![frmWklyDialog]![StartDate]) And cdate([Forms]![frmWklyDialog]![StartDate])+7
0
 
LVL 44

Expert Comment

by:GRayL
ID: 22692619
In a control source in a dialog box, you cannot enter a query.  Please be very specific about what you are tryin to do.
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 22694075
I would change the code only slightly to ensure that you get date entries (cos if you don't your query will fail):
Private Sub Command0_Click()

On Error GoTo Err_Command0_Click

    Dim stDocName As String

    Dim stWhere As String

    Dim myStartDate as String

 

myStartDate = nz(Me.txtStartDate,"Empty")
 

If Not IsDate(myStartDate) then

    Msgbox "You must enter a date for the start",vbokonly,"Error"

    Me.txtStartDate.Setfocus

End if
 

    stDocName = "Report1"

    stWhere = "Last_Update_Date BETWEEN #" & format(myStartDate,"dd-mmm-yyyy") & "# AND #" & DateAdd("m", 1, format(myStartDate,"dd-mmm-yyyy")) & "#"

    DoCmd.OpenReport stDocName, acPreview, , stWhere

 

Exit_Command0_Click:

    Exit Sub

 

Err_Command0_Click:

    MsgBox err.Description

    Resume Exit_Command0_Click

End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Computers reporting Windows patches applied 14 81
Sub Reports 8 23
SQL Query resolving a string conversion issue 26 39
linked subforms are yielding error:  ... (800110108) 3 16
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now