473,804 Members | 3,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open the report conditionally

Hi All,

I am trying to open the report conditionally from the dialogue box
form. In the form there are three field.

cboEmployees
StartDate
EndDate

I have used these field in criteria to open the report. If I use the
field name and between command, the report is not opening but when I
use the greater than and less than equal to, the report is opening but
there is no records. The used code are as follows:

Private Sub cmdPrint_Click( )
Dim strSelectEmp As String

'strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' AND
(datevalue([OverTimeDate]) Between '" & DateValue(Me.St artDate) And
DateValue(Me.En dDate) & "')"
strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' and
(datevalue([overtimedate]) >= '" & DateValue(Me.St artDate) & "' and
datevalue([overtimedate]) <= '" & DateValue(Me.En dDate) & "')"

DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, ,
strSelectEmp
End Sub

Can anybody help me to solve the problem.

Thanks in advance

Naushad
Aug 20 '08 #1
3 2076
This example is designed to make it really easy to add more filter boxes if
you ever need to. It solves several problems:

1. It applies the filter only if there is something in the controls (not if
they are left null.)

2. It checks the dates are valid.

3. It formats the dates the way JET expects, and adds the # delimiter. (Do
NOT change the Const line to match your regional settings: leave it as is.)

4. It illustrates how to print the contents of the filter string into the
Immediate Window. After running it, press Ctrl+G to see what the filter
looked like.

5. If your OverTimeDate field has a time component as well as the date, it
still returns the last date (by asking for 'less than the next day.')

6. If the person's name contains an apostropy, it still works (by using
double-quotes.)

Private Sub cmdPrint_Click( )
Dim strWhere As String
Dim lngLen As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"

If Not IsNull(Me.cboEm ployees) Then
strWhere = strWhere & "(EmpName = """ & Me.cboEmployees & """) AND "
End If

If IsDate(Me.Start Date) Then
strWhere =strWhere & "(OverTimeD ate >= " & _
Format(Me.Start Date, strcJetDate) & ") AND "
End If

If IsDate(Me.EndDa te) Then
strWhere =strWhere & "(OverTimeD ate < " & _
Format(Me.EndDa te + 1, strcJetDate) & ") AND "
End If

'Chop off the trailing " AND "
lngLen=Len(strW here) - 5
If lngLen 0 Then
strWhere = Left$(strWhere, lngLen)
End If

Debug.Print strWhere
DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, , strWhere
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Naushad" <nh*****@kockw. comwrote in message
news:13******** *************** ***********@w7g 2000hsa.googleg roups.com...
>
I am trying to open the report conditionally from the dialogue box
form. In the form there are three field.

cboEmployees
StartDate
EndDate

I have used these field in criteria to open the report. If I use the
field name and between command, the report is not opening but when I
use the greater than and less than equal to, the report is opening but
there is no records. The used code are as follows:

Private Sub cmdPrint_Click( )
Dim strSelectEmp As String

'strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' AND
(datevalue([OverTimeDate]) Between '" & DateValue(Me.St artDate) And
DateValue(Me.En dDate) & "')"
strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' and
(datevalue([overtimedate]) >= '" & DateValue(Me.St artDate) & "' and
datevalue([overtimedate]) <= '" & DateValue(Me.En dDate) & "')"

DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, ,
strSelectEmp
End Sub

Can anybody help me to solve the problem.

Thanks in advance

Naushad
Aug 20 '08 #2
Thanks for your support. I have used your code to open the report. I
am phasing the same problem that means the report is opening but
there is no records. I don't know why there is no records in the
report. I have used the datevalue function also.

Please solve this problem.

Thanks and regards

On Aug 20, 2:54*pm, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
This example is designed to make it really easy to add more filter boxes if
you ever need to. It solves several problems:

1. It applies the filter only if there is something in the controls (not if
they are left null.)

2. It checks the dates are valid.

3. It formats the dates the way JET expects, and adds the # delimiter. (Do
NOT change the Const line to match your regional settings: leave it as is..)

4. It illustrates how to print the contents of the filter string into the
Immediate Window. After running it, press Ctrl+G to see what the filter
looked like.

5. If your OverTimeDate field has a time component as well as the date, it
still returns the last date (by asking for 'less than the next day.')

6. If the person's name contains an apostropy, it still works (by using
double-quotes.)

Private Sub cmdPrint_Click( )
* * Dim strWhere As String
* * Dim lngLen As Long
* * Const strcJetDate = "\#mm\/dd\/yyyy\#"

* * If Not IsNull(Me.cboEm ployees) Then
* * * * strWhere = strWhere & "(EmpName = """ & Me.cboEmployees & """) AND "
* * End If

* * If IsDate(Me.Start Date) Then
* * * * strWhere =strWhere & "(OverTimeD ate >= " & _
* * * * * * Format(Me.Start Date, strcJetDate) & ") AND "
* * End If

* * If IsDate(Me.EndDa te) Then
* * * * strWhere =strWhere & "(OverTimeD ate < " & _
* * * * * * Format(Me.EndDa te + 1, strcJetDate) & ") AND "
* * End If

* * 'Chop off the trailing " AND "
* * lngLen=Len(strW here) - 5
* * If lngLen 0 Then
* * * * strWhere = Left$(strWhere, lngLen)
* * End *If

* * Debug.Print strWhere
* * DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, , strWhere
End Sub

--
Allen Browne - Microsoft MVP. *Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Naushad" <nhai...@kockw. comwrote in message

news:13******** *************** ***********@w7g 2000hsa.googleg roups.com...


I am trying to open the report conditionally from the dialogue box
form. In the form there are three field.
cboEmployees
StartDate
EndDate
I have used these field in criteria to open the report. If I use the
field name and between command, the report is not opening but when I
use the greater than and less than equal to, the report is opening but
there is no records. The used *code are as follows:
Private Sub cmdPrint_Click( )
* *Dim strSelectEmp As String
* *'strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' *AND
(datevalue([OverTimeDate]) Between '" & DateValue(Me.St artDate) And
DateValue(Me.En dDate) & "')"
* *strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' and
(datevalue([overtimedate]) >= '" & DateValue(Me.St artDate) & "' and
datevalue([overtimedate]) <= '" & DateValue(Me.En dDate) & "')"
* DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, ,
strSelectEmp
End Sub
Can anybody help me to solve the problem.
Thanks in advance
Naushad- Hide quoted text -

- Show quoted text -
Aug 25 '08 #3
"Naushad" <nh*****@kockw. comwrote in message
news:cd******** *************** ***********@x35 g2000hsb.google groups.com...
>
Please solve this problem.
We are not here to solve your problems. The best we can do is give you some
clues where to look, so you can solve them.
Thanks for your support. I have used your code to open the report.
I am phasing the same problem that means the report is opening
but there is no records. I don't know why there is no records in the
report. I have used the datevalue function also.
After you open the report and it has no records, open the Immediate Window
(Ctrl+G) and see what you got printed there. Try that as the criteria in a
query similar to the report's record source, and see why you get no results.

On Aug 20, 2:54 pm, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
This example is designed to make it really easy to add more filter boxes
if
you ever need to. It solves several problems:

1. It applies the filter only if there is something in the controls (not
if
they are left null.)

2. It checks the dates are valid.

3. It formats the dates the way JET expects, and adds the # delimiter. (Do
NOT change the Const line to match your regional settings: leave it as
is.)

4. It illustrates how to print the contents of the filter string into the
Immediate Window. After running it, press Ctrl+G to see what the filter
looked like.

5. If your OverTimeDate field has a time component as well as the date, it
still returns the last date (by asking for 'less than the next day.')

6. If the person's name contains an apostropy, it still works (by using
double-quotes.)

Private Sub cmdPrint_Click( )
Dim strWhere As String
Dim lngLen As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"

If Not IsNull(Me.cboEm ployees) Then
strWhere = strWhere & "(EmpName = """ & Me.cboEmployees & """) AND "
End If

If IsDate(Me.Start Date) Then
strWhere =strWhere & "(OverTimeD ate >= " & _
Format(Me.Start Date, strcJetDate) & ") AND "
End If

If IsDate(Me.EndDa te) Then
strWhere =strWhere & "(OverTimeD ate < " & _
Format(Me.EndDa te + 1, strcJetDate) & ") AND "
End If

'Chop off the trailing " AND "
lngLen=Len(strW here) - 5
If lngLen 0 Then
strWhere = Left$(strWhere, lngLen)
End If

Debug.Print strWhere
DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, , strWhere
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Naushad" <nhai...@kockw. comwrote in message

news:13******** *************** ***********@w7g 2000hsa.googleg roups.com...


I am trying to open the report conditionally from the dialogue box
form. In the form there are three field.
cboEmployees
StartDate
EndDate
I have used these field in criteria to open the report. If I use the
field name and between command, the report is not opening but when I
use the greater than and less than equal to, the report is opening but
there is no records. The used code are as follows:
Private Sub cmdPrint_Click( )
Dim strSelectEmp As String
'strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' AND
(datevalue([OverTimeDate]) Between '" & DateValue(Me.St artDate) And
DateValue(Me.En dDate) & "')"
strSelectEmp = "[EmpName] = '" & Me.cboEmployees & "' and
(datevalue([overtimedate]) >= '" & DateValue(Me.St artDate) & "' and
datevalue([overtimedate]) <= '" & DateValue(Me.En dDate) & "')"
DoCmd.OpenRepor t "rptOverTimeApp roval", acViewPreview, ,
strSelectEmp
End Sub
Can anybody help me to solve the problem.
Thanks in advance
Naushad- Hide quoted text -

- Show quoted text -
Aug 25 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4924
by: Miguel | last post by:
I have reviewed the many postings on this topic and understand the principle, but am not sure where in my case to apply trapping an error. I have created a form to supply parameters to a report. I click on the command button to open the report, the form opens as it should and the parameters are entered. Upon clicking on "OK," the underlying query is executed. It is at this point, the the error message appears. The dialog box disappers as...
12
2249
by: Orchid | last post by:
Hello all, I have different version of reports which used for different months. For example, I am using report version 1 up to September, but we have some design changes on the report for October, so I created report version 2. I want a same Command Button to open the appropriated version report for the specific month. I create a table with the following Fields: Month, ReportID, ReportToOpen (this is the exact report name). On a form,...
0
306
by: rinmanb70 | last post by:
I open a report with a button on a form and I'd like to have the report open to the last page. I tried using sendkeys and it works when I manually open the report from Reports on the msaccess screen, but when I use the button on the form the report opens to the first page. It looks like the problem there is that the sendkeys command is processed before the report opens, so the sendkeys command is focused on the form and not on the report...
4
46016
by: magmike | last post by:
I've created a report for the purpose of printing a one page summary of a record. Of course, when I created the report, it gives me a page on every record. Can I create a button to open that report with just the results of that current record? And how do I modify the report to accept the buttons command? Thanks!
5
48534
by: Piedone | last post by:
Hi! I have experienced a a really odd problem when writing an Access application. I would programatically open a report (because i need to pass a value to it) with DoCmd.OpenReport. I would like to open it for viewing, not in print preview (as there the recordsource couldn't be modified anymore), like when you open it from the command bar with the button "Report View". The odd thing is, that apparently there's no way to simply view the...
7
2931
by: martin DH | last post by:
Hello, I have a report that I open that pull its data from a form that builds a where string. Opening the report first opens the form, where I enter criteria, and then pulls matching records from a table, opens the report, and closes the form. The code on the report is below. I used this code on a similar report that also pulled its data from a form (the difference was that that form supplied criteria to an actual query - my new form...
4
9669
by: Phil Stanton | last post by:
I am opening a report (in Preview) from a menu system I use the following code if there is no data in a report Private Sub Report_NoData(Cancel As Integer) MsgBox "There are no errors in Membership Head of Families", vbInformation Cancel = True
4
4504
by: pacarv | last post by:
I've created a database in Access 2003 with multiple reports that are accessable from the switchboard. The switchboard also has a print button. The user selects the report from the menu which then opens in another window for the user to preview. I am trying to enable the print button to print the open report however the print macro prints the switchboard instead. Can anyone provide me with the code needed to accomplish my goal? I have no...
5
9060
by: tetsuo2030 | last post by:
Hey All, I’ve reached another aesthetic stumbling block: I have a report that lists all the widgets on Optimus Prime with the fields "Widget Number" and "ID Number" (and some other fields). Sometimes the widgets get ID numbers, and sometimes they don't; the widgets without ID numbers get the value "n/a"--this value is found in the table/query the report is based upon. What I want to happen is have the ID numbers be underlined if they have...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.