Solved

DateField in the From date and To date

Posted on 2014-02-17
6
279 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 37

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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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 50

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

Independent Software Vendors: 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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

752 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