Solved

DateField in the From date and To date

Posted on 2014-02-17
6
274 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
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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 34

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 119

Expert Comment

by:Rey Obrero
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 49

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
At the beginning of the year, the IT world was taken hostage by the shareholders of LogMeIn. Their free product, which had been free for ten years, all of the sudden became a "pay" product. Now, I am the first person who will say that software maker…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

12 Experts available now in Live!

Get 1:1 Help Now