473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Select Report to Open by CheckBox

NeoPa,

I am just about done. Can you throw me another bone on another stump I hit. I have a form that contains information that can be applied to two reports. A yes/no field distinguishes what type of report it would refer to(for example). If I install a command button on the form how can I get it to got to (for example) report1 with all field data when the yes/no field is yes.

David
Mar 18 '08 #1
19 2215
NeoPa
32,556 Expert Mod 16PB
This thread has been split from the Getting Rid of #Error thread as it is a separate question.

I'm happy enough to post an answer, but we request that questions are kept to their own threads for manageability.
Mar 18 '08 #2
NeoPa
32,556 Expert Mod 16PB
Assuming you have a form (frmChoose) with a CommandButton (cmdReport) and a CheckBox (chkNight) on it. You want to run one report (rptDay) if chkNight is False and another (rptNight) if it's True.

You would have an OnClick procedure for cmdReport something like the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReport_Click()
  2.   Dim strReport As String
  3.  
  4.   strReport = IIf(Me.chkNight, "rptNight", "rptDay")
  5.   Call DoCmd.OpenReport(strReport, acViewPreview)
  6. End Sub
Clearly this is at its simplest, but it should give you the idea of how to go about things.

Good luck :)
Mar 18 '08 #3
Assuming you have a form (frmChoose) with a CommandButton (cmdReport) and a CheckBox (chkNight) on it. You want to run one report (rptDay) if chkNight is False and another (rptNight) if it's True.

You would have an OnClick procedure for cmdReport something like the following :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReport_Click()
  2.   Dim strReport As String
  3.  
  4.   strReport = IIf(Me.chkNight, "rptNight", "rptDay")
  5.   Call DoCmd.OpenReport(strReport, acViewPreview)
  6. End Sub
Clearly this is at its simplest, but it should give you the idea of how to go about things.

Good luck :)

Neopa,

How do I cobine your code for the Checkbox with the the code that already exist their(code below). I would like your code to change however to only send data to rptNight only if the box is checked and it does nothing when it is unchecked. How do we go about doing this? You can change the coding below to reflect this if you want.

Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintCCCertificates_Click()
  2. On Error GoTo Err_PrintCCCertificates_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "(Attendance) - Matt's signature"
  7.  
  8.     If Me.Dirty = True Then Me.Dirty = False
  9.  
  10. DoCmd.OpenReport stDocName, acPreview, , "[Instructor] = '" & Me![Instructor] & "'" & _
  11.                  " And [InstTitle] = '" & Me![InstTitle] & "' And [CertSerialNum] > " & _
  12.                  lngLastValueEntered
  13.  
  14.     'DoCmd.OpenReport stDocName, acPreview (keep if need to change back to original script)
  15.  
  16. Exit_PrintCCCertificates_Click:
  17.     Exit Sub
  18.  
  19. Err_PrintCCCertificates_Click:
  20.     MsgBox Err.Description
  21.     Resume Exit_PrintCCCertificates_Click
  22.  
  23. End Sub
David
Mar 26 '08 #4
NeoPa
32,556 Expert Mod 16PB
My original code would then look like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReport_Click()
  2.   If Me.chkNight Then Call DoCmd.OpenReport("rptNight", acViewPreview)
  3. End Sub
Let me know if you need help changing your code to reflect this.
Mar 26 '08 #5
My original code would then look like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReport_Click()
  2.   If Me.chkNight Then Call DoCmd.OpenReport("rptNight", acViewPreview)
  3. End Sub
Let me know if you need help changing your code to reflect this.

Neopa,

Yes I do need help. I am not sure where to put your code at in the previous coding I sent out.

David
Mar 26 '08 #6
NeoPa
32,556 Expert Mod 16PB
I can't put any code in as you haven't shared the name of your CheckBox control?

With this, and assuming all else is equal and you want the report only to run when the value of the CheckBox is True, I can redo your code in the way you want.
Mar 26 '08 #7
The control name of the Checkbox is "CCClass". I just want to put clarity to the coding. When the box is checked I do want the report only to run when the value of the Checkbox is True but also I want only the input that was entered for the present day (the control name of the date is "CertPrintDate") and not previous days in conjunction with the text above to where it will work. Is that all you need.

David
Mar 26 '08 #8
NeoPa
32,556 Expert Mod 16PB
I think it does - and congratulations on reaching full-member status :)

I was thinking of using the same logic for the filtering as you already had.

I will try to get back to this sometime this evening for you.
Mar 26 '08 #9
NeoPa
32,556 Expert Mod 16PB
Try this (I'm off home now for the evening so if there are any problems or questions they'll probably have to wait until tomorrow) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintCCCertificates_Click()
  2. On Error GoTo Err_PrintCCCertificates_Click
  3.  
  4.   Dim stDocName As String, strWhere As String
  5.  
  6.   If Me.Dirty = True Then Me.Dirty = False
  7.  
  8.   If Me.CCClass Then
  9.     stDocName = "(Attendance) - Matt's signature"
  10.     strWhere = "([Instructor] = '%I') AND " & _
  11.                "([InstTitle] = '%T') AND " & _
  12.                "([CertSerialNum] > %S) AND " & _
  13.                "([CertPrintDate] = #%D#)"
  14.     strWhere = Replace(strWhere, "%I", Me.[Instructor])
  15.     strWhere = Replace(strWhere, "%T", Me.[InstTitle])
  16.     strWhere = Replace(strWhere, "%S", lngLastValueEntered)
  17.     strWhere = Replace(strWhere, "%D", Format(Date(), "m/d/yyyy"))
  18.  
  19.     Call DoCmd.OpenReport(stDocName, acPreview, , strWhere)
  20.     'DoCmd.OpenReport stDocName, acPreview (keep if need to change back to original script)
  21.   End If
  22.  
  23. Exit_PrintCCCertificates_Click:
  24.   Exit Sub
  25.  
  26. Err_PrintCCCertificates_Click:
  27.   MsgBox Err.Description
  28.   Resume Exit_PrintCCCertificates_Click
  29.  
  30. End Sub
Mar 26 '08 #10
NeoPa
32,556 Expert Mod 16PB
I included the date selection as well as the previous selections you already had (from post #4).

Let me know how you get on with this.
Mar 27 '08 #11
I included the date selection as well as the previous selections you already had (from post #4).

Let me know how you get on with this.
Neopa,

I installed the coding but now instead of coming up with all recordson the report now it comes up with no records. I wasnt sure what the date is suppose to do. Actually I am confused on that because my form has three different dates one for start date of class, one for end date of class and one for date of certificate printing. I am going to assume that the date is based off of the computer not the form.

David
Mar 27 '08 #12
Neopa,

I installed the coding but now instead of coming up with all recordson the report now it comes up with no records. I wasnt sure what the date is suppose to do. Actually I am confused on that because my form has three different dates one for start date of class, one for end date of class and one for date of certificate printing. I am going to assume that the date is based off of the computer not the form.

David
Neopa,

I corrected some coding that was previously there prior to me using yours and now a window pops up and says

Extra) in query expression
Expand|Select|Wrap|Line Numbers
  1. (([Instructor] ='Chris McJean')
and
Expand|Select|Wrap|Line Numbers
  1. ([InstTitle] = 'Technical Instructor/Developer')
and
Expand|Select|Wrap|Line Numbers
  1. ([CertSerialNum] >)
and
Expand|Select|Wrap|Line Numbers
  1. ([CertPrintDat] = #27 March 2008#))

What do you think could be the problem?


David
Mar 27 '08 #13
NeoPa
32,556 Expert Mod 16PB
Your [CertSerialNum] line has no comparison value in it. This explains your error message.

As to your logic, that's another matter. Can you post the whole module just for reference, then I can look through it for precise answers.
Mar 28 '08 #14
Your [CertSerialNum] line has no comparison value in it. This explains your error message.

As to your logic, that's another matter. Can you post the whole module just for reference, then I can look through it for precise answers.
NeoPa,

Here is the whole module

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private lngLastValueEntered As Long
  3.  
  4. Private Sub CCClass_AfterUpdate()
  5. Me![CCClass].DefaultValue = "'" & Me![CCClass] & "'"
  6. End Sub
  7.  
  8. Private Sub CertPrintDate_AfterUpdate()
  9. Me![CertPrintDate].DefaultValue = "'" & Me![CertPrintDate] & "'"
  10. End Sub
  11.  
  12. Private Sub ClassSize_AfterUpdate()
  13. Me![ClassSize].DefaultValue = "'" & Me![ClassSize] & "'"
  14. End Sub
  15.  
  16. Private Sub Detail_Click()
  17.  
  18. End Sub
  19.  
  20. Private Sub Form_AfterUpdate()
  21.  
  22. End Sub
  23.  
  24. Private Sub Form_Open(Cancel As Integer)
  25.   lngLastValueEntered = DLast("[CertSerialNum]", "Master Cert Database")
  26. End Sub
  27.  
  28. Private Sub StudentCompany_AfterUpdate()
  29. Me![StudentCompany].DefaultValue = "'" & Me![StudentCompany] & "'"
  30. End Sub
  31.  
  32. Private Sub StudentName_AfterUpdate()
  33. Me![StudentName].DefaultValue = "'" & Me![StudentName] & "'"
  34. End Sub
  35.  
  36. Private Sub System_AfterUpdate()
  37. Me![System].DefaultValue = "'" & Me![System] & "'"
  38. End Sub
  39.  
  40. Private Sub CloseForm_Click()
  41. On Error GoTo Err_CloseForm_Click
  42.  
  43.  
  44.     DoCmd.Close
  45.  
  46. Exit_CloseForm_Click:
  47.     Exit Sub
  48.  
  49. Err_CloseForm_Click:
  50.     MsgBox Err.Description
  51.     Resume Exit_CloseForm_Click
  52.  
  53. End Sub
  54.  
  55.  
  56. Private Sub PLMCertificates_Click()
  57. On Error GoTo Err_PLMCertificates_Click
  58.  
  59.     Dim stDocName As String
  60.  
  61.     stDocName = "ChristineMcLaurinCert"
  62.     DoCmd.OpenReport stDocName, acPreview
  63.  
  64. Exit_PLMCertificates_Click:
  65.     Exit Sub
  66.  
  67. Err_PLMCertificates_Click:
  68.     MsgBox Err.Description
  69.     Resume Exit_PLMCertificates_Click
  70.  
  71. End Sub
  72.  
  73.  
  74. Private Sub PCCCertificates_Click()
  75. On Error GoTo Err_PCCCertificates_Click
  76.  
  77.   Dim stDocName As String, strWhere As String
  78.  
  79.   If Me.Dirty = True Then Me.Dirty = False
  80.  
  81.   If Me.CCClass Then
  82.     stDocName = "(Attendance) - Matt's signature"
  83.     strWhere = "([Instructor] = '%I') AND " & _
  84.                "([InstTitle] = '%T') AND " & _
  85.                "([CertSerialNum] > %S) AND " & _
  86.                "([CertPrintDate] = #%D#)"
  87.     strWhere = Replace(strWhere, "%I", Me.[Instructor])
  88.     strWhere = Replace(strWhere, "%T", Me.[InstTitle])
  89.     strWhere = Replace(strWhere, "%S", lngLastValueEntered)
  90.     strWhere = Replace(strWhere, "%D", Format(Date, "dd/mmmm/yyyy"))
  91.  
  92.     Call DoCmd.OpenReport(stDocName, acPreview, , strWhere)
  93.     'DoCmd.OpenReport stDocName, acPreview (keep if need to change back to original script)
  94.   End If
  95.  
  96. Exit_PCCCertificates_Click:
  97.   Exit Sub
  98.  
  99. Err_PCCCertificates_Click:
  100.   MsgBox Err.Description
  101.   Resume Exit_PCCCertificates_Click
  102.  
  103. End Sub
David
Mar 28 '08 #15
NeoPa
32,556 Expert Mod 16PB
Right, it would seem that there are some discrepancies between the code posted and the results you claim in the error message posted in post #13. Whatever lngLastValueEntered is set to, the ([CertSerialNum] > n) part must resolve to a valid number as far as I can see with your posted code (See lines #83 through #89).

Also, the date shown doesn't match the format specified in line #90 (which doesn't match the format shown in my post #10 either). Your formatting should work, but only because Access does some non-standard things to cover all bases.

I assume this is your most recent code, so what error messages (as accurately as possible please) do you get when running this code. When we've cleared all the reported error messages and compiled the project, then we can look at the logic producing what we need.

Often the process miraculously starts to work once the syntax etc errors are sorted out.
Mar 28 '08 #16
NeoPa,

I inserted the number after the CertSerialNum and when cmd button is executed it says invalid use of Null. (I didn't quite understand about the date. I know I change it's format in your original coding to reflect what is in the form)

David
Mar 28 '08 #17
NeoPa
32,556 Expert Mod 16PB
NeoPa,

I inserted the number after the CertSerialNum and when cmd button is executed it says invalid use of Null. (I didn't quite understand about the date. I know I change it's format in your original coding to reflect what is in the form)

David
I'm sorry David, you need to be a lot more precise than this. I can't even guess what you're trying to say about what you did and got. Remember I stressed the info must be clear (I can't see it directly you see - I only have what you tell me to go on).

The parenthesised stuff (surrounded by () characters) I get. You should not really be thinking along those lines as the code is prepared for processing as SQL - not how it looks on a form.

The date is actually stored as a real number. SQL doesn't care about that when dealing with date literals. It has its own rules (See Literal DateTimes and Their Delimiters (#)).
Mar 28 '08 #18
I'm sorry David, you need to be a lot more precise than this. I can't even guess what you're trying to say about what you did and got. Remember I stressed the info must be clear (I can't see it directly you see - I only have what you tell me to go on).

The parenthesised stuff (surrounded by () characters) I get. You should not really be thinking along those lines as the code is prepared for processing as SQL - not how it looks on a form.

The date is actually stored as a real number. SQL doesn't care about that when dealing with date literals. It has its own rules (See Literal DateTimes and Their Delimiters (#)).
Sorry about that NeoPa,

On line 85 I change its coding to:
Expand|Select|Wrap|Line Numbers
  1. "([CertSerialNum] > 367288 %S) AND " & _
Next I executed line 74 and its coding (I did this from a command button on a [Form] in form view which is labeled PCCCertificates which is also linked to line 74 and it's coding).

Once line 74 and it's coding was complete with it's execution, a msgbox popped up and sayed "Invalid use of Null".

I acknowledged it by pressing OK and the msg box went away
and that is it.

David
Mar 28 '08 #19
NeoPa
32,556 Expert Mod 16PB
Can you add the following line to your code after line #90 and let me know what it shows when run.
Expand|Select|Wrap|Line Numbers
  1. Call MsgBox(strWhere)
Mar 29 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jaya | last post by:
Hi, I am using asp.net to pass parameters from .aspx page to my Microsoft reporting service. My .aspx page has checkbox. If it is checked it the chekbox should pass value =0 to my report <INPUT...
4
by: schmidtmic | last post by:
I have a table that contains 20 checkbox fields. Each checkbox corrisponds to an Score amount. For Example: Checkbox1 is worth 10 points Checkbox2 is worth 5 points Checkbox3 is worth 2...
0
by: bonita | last post by:
In my ASP.NET page, I have 2 checkboxes for users to choose which crystal report they want to display. These two reports use different tables. If report1 has been choosen and displayed in the...
0
by: New2ASP | last post by:
Thanks everyone in advance for your help. I am fairly new to web development but an experienced window-based developer. Here's the structure of my Gridview Column 1 : Checkbox with SelectAll...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
11
by: radink | last post by:
Hey All, I have a report that I would like to show a word on based on if a field is checked in a form. For example. The form has a check box called Fee. If that is checked, I want the word Paid...
6
by: alphaomega3 | last post by:
I'm back with a new set of problems with the old NCR database from a year ago. I have a form that is for Nonconformance Entry. In the process of entering this form if the supplier for the...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
2
by: deegeorge | last post by:
Hi, I have an aspx form. In that i have a check box for Credit card payment. When i am submitting that form it need to open a crystal report. If the checkbox is checked the textbox field in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.