Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DateField in the From date and To date

Posted on 2014-02-17
6
Medium Priority
?
282 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 39

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
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!

 
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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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.
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…

704 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