Solved

DateField in the From date and To date

Posted on 2014-02-17
6
280 Views
Last Modified: 2014-02-21
Hi,

onclick event I have this code.  the problem is I am not getting any result within the date range result. I know that I have data with the date range I am putting in the form.

1. I don't know why I have this [DateField] when I open the report.  (why do I need that?)
2.  I am not able to generate any output.

Private Sub CmdDailyContainment_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Report_1_MTD_Daily_Containment"

If IsDate(Me.FromTxt) And IsDate(Me.ToTxt) Then
    If Me.ToTxt > Me.FromTxt Then
    Else
        MsgBox "End Date must be greater than start date.", vbOKOnly
        Me.ToTxt.SetFocus
        Exit Sub
    End If
Else
   MsgBox "A valid date range is required to run this report.", vbOKOnly
    Me.FromTxt.SetFocus
    Exit Sub
End If

stLinkCriteria = "[DateField] BETWEEN " & Me.FromTxt & " AND " & Me.ToTxt
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

end
0
Comment
Question by:lulu50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39865030
you have to change [DateField] with the actual name of the field for the date in your report.

also use this code

 stLinkCriteria = "[DateField] BETWEEN #" & Me.FromTxt & "# And #" & Me.ToTxt & "#"
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39865100
If you go back to your previous thread
http://www.experts-exchange.com/Software/System_Utilities/Remote_Access/Q_28364935.html

You will see that my example included the Pound signs.
0
 

Author Comment

by:lulu50
ID: 39865334
Rey,

Can you please, tell me what you mean with the actual name of the field

on my form I have two input box one ToTxt and the second is FromTxt

I am new to access so I am not sure what I need to replace it with

 stLinkCriteria = "[DateField] BETWEEN #" & Me.FromTxt & "# And #" & Me.ToTxt & "#"
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39865386
in the Record Source of your report  "Report_1_MTD_Daily_Containment"

what is the name of the field that shows the Dates that you want to filter?

get the name of that field and use that in your code,
assuming the name of the field is "Date Purchased"

the code will be

 stLinkCriteria = "[Date Purchased] BETWEEN #" & Me.FromTxt & "# And #" & Me.ToTxt & "#"
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39866708
You should do like this:
Private Sub CmdDailyContainment_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Report_1_MTD_Daily_Containment"

If IsDate(Me!FromTxt) And IsDate(Me!ToTxt) Then
    If DateValue(Me!ToTxt) < DateValue(Me!FromTxt) Then
        MsgBox "End Date must be greater than start date.", vbInformation + vbOKOnly
        Me!ToTxt.SetFocus
        Exit Sub
    End If
Else
    MsgBox "A valid date range is required to run this report.", vbInformation + vbOKOnly
    Me!FromTxt.SetFocus
    Exit Sub
End If

stLinkCriteria = "[DateField] BETWEEN #" & Format(Me!FromTxt, "yyyy\/mm\/dd") & "# AND #" & Format(Me!ToTxt, "yyyy\/mm\/dd") & "#"

DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

End 

Open in new window

/gustav
0
 

Author Closing Comment

by:lulu50
ID: 39877989
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

617 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