Solved

DateField in the From date and To date

Posted on 2014-02-17
6
276 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 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 35

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

777 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