Can someone help me with this funny problem?
I just created a custom criteria form that a user enters data to open a report.
.
I have two unbound check boxes namely 1. chkshowcredits and 2. chknocredits that a user must select/tick one of them before opening the report.
The on click event (code) of the OK button on the form to preview the report is below: - Private Sub Command6_Click()
-
If IsNull(Me.Oyear) = True Or IsNull(Me.ndate) = True Then
-
MsgBox "One of the required dates is missing", vbCritical + vbOKOnly, "Date Error"
-
End If
-
If Me.Oyear <= Me.ndate Then
-
MsgBox "Oldest date must be less than Newst date", vbCritical + vbOKOnly, "Date Error"
-
Exit Sub
-
End If
-
- If me.chkshowcredits.Value = True Then'error occurs here
-
DoCmd.OpenReport "Summary with Credits", acViewPreview
- ElseIf me.chknocredits.Value = True Then'error occurs here
-
DoCmd.OpenReport "Summary With No Credits", acViewPreview
-
Else
-
MsgBox "Select an option to show or not to show credits in the report", vbCritical + vbOKOnly, "Data Missing"
-
End If
-
End Sub
-
-
-
Rest of the validation in the code above is fine but the error message occurs exactly at code line#10 and could possibly occur again at line#12, i.e when I debug it. An this is to do with the two unbound check boxes.
What is the problem.? I just want the user to tick one of the check boxes to open a particular report based on the check box ticked.
I am I wrong somewhere.?
Can one smart person help me out here. I tried to solve this but its hurting my brain.
Thanks..
@ahmedtharwat19
Assuming: - There are no Syntax Errors on the Control Names.
- OYear and nDate are Valid Dates.
- The Check Boxes are mutually exclusive.
- The report Names are correct.
- If the above assumptions are all correct, the code listed will work fine.
- If IsNull(Me.OYear) Or IsNull(Me.nDate) Then
-
MsgBox "One of the required dates is missing", vbCritical + vbOKOnly, "Date Error"
-
Exit Sub
-
End If
-
-
If Not IsDate(Me.OYear) Or Not IsDate(Me.nDate) Then
-
MsgBox "At least one Invalid Date", vbCritical + vbOKOnly, "Invalid Date Error"
-
Exit Sub
-
End If
-
-
If CDate(Me.OYear) <= CDate(Me.nDate) Then
-
MsgBox "Oldest date must be less than Newest date", vbCritical + vbOKOnly, "Date Error"
-
Exit Sub
-
End If
-
-
If Me.chkShowCredits Then
-
DoCmd.OpenReport "Summary with Credits", acViewPreview
-
ElseIf Me.chkNoCredits Then
-
DoCmd.OpenReport "Summary With No Credits", acViewPreview
-
Else
-
MsgBox "Select an option to show or not to show credits in the report", _
-
vbCritical + vbOKOnly, "Data Missing"
-
End If
11 7160
HI Jerry Maiapu - If Me.chkshowcredits.Value = True Then'error occurs here
-
DoCmd.OpenReport "Summary with Credits", acViewPreview
-
ElseIf Me.chknocredits.Value = True Then'error occurs here
I THINK THE ERROR IN THIS CODE REASON TO
THE VALUE IS NOT EQUAL TRUE OR FALSE JUST EQUAL A NUMBER
TRUE=1,FALSE=0 IN CHECKBOX
TRY THIS CODE AND TELL ME - If Me.chkshowcredits.Value = 1 Then 'EDIT BY MEDO
-
DoCmd.OpenReport "Summary with Credits", acViewPreview
-
ElseIf Me.chknocredits.Value = 1 Then'EDIT BY MEDO
BEST REGARDS ,
AHMED THARWAT( MEDO)
@ahmedtharwat19 AHMED THARWAT(MEDO),
Thank you in trying to help but I tried that too and still the error message is persisting to pop up.
After many attempts I have just done away with the check box business and am using a combo box for the users to select from the two text values, YES & NO which is fine. However if you still have some solution/suggestions do post it.
Thank you.
Jerry
@Jerry Maiapu
Jerry,
I Need To Help.
Can You Attach The sample Problem To solve It.
Thank you in showing interest to help. It is really kind of you.
Ok, first of all I cannot attach the the mdb file coz it is about 17mb but can I give you the form property details and maybe a screen shot of the form?
Instead of adding two individual checkboxes add an option group with two possible values. Now the values will default to 1 and 2. You then use a SELECT CASE function to decide what the selection triggers. Something like the following: - 'lets assume you name the option group object as rptFrame
-
'In the after update event of that object.
-
Private Sub rptFrame_AfterUpdate()
-
-
SELECT CASE rptFrame
-
-
Case 1
-
Docmd.OpenReport "Report1"
-
-
Case 2
-
Docmd.OpenReport "Report2"
-
-
END SELECT
-
-
End Sub
Jerry Maiapu,
Do It In Option Group, I Think It The Best Of You,
Because The First If The Value of CheckBox1 Is True And You You Check The Secound CheckBox Value To Be True,The First Still True, But In Option Group This Problem Will Done.
I Attach The Sample For That. Best Regards,
Ahmed Tharwat (Medo)
@ahmedtharwat19
Assuming: - There are no Syntax Errors on the Control Names.
- OYear and nDate are Valid Dates.
- The Check Boxes are mutually exclusive.
- The report Names are correct.
- If the above assumptions are all correct, the code listed will work fine.
- If IsNull(Me.OYear) Or IsNull(Me.nDate) Then
-
MsgBox "One of the required dates is missing", vbCritical + vbOKOnly, "Date Error"
-
Exit Sub
-
End If
-
-
If Not IsDate(Me.OYear) Or Not IsDate(Me.nDate) Then
-
MsgBox "At least one Invalid Date", vbCritical + vbOKOnly, "Invalid Date Error"
-
Exit Sub
-
End If
-
-
If CDate(Me.OYear) <= CDate(Me.nDate) Then
-
MsgBox "Oldest date must be less than Newest date", vbCritical + vbOKOnly, "Date Error"
-
Exit Sub
-
End If
-
-
If Me.chkShowCredits Then
-
DoCmd.OpenReport "Summary with Credits", acViewPreview
-
ElseIf Me.chkNoCredits Then
-
DoCmd.OpenReport "Summary With No Credits", acViewPreview
-
Else
-
MsgBox "Select an option to show or not to show credits in the report", _
-
vbCritical + vbOKOnly, "Data Missing"
-
End If
I Here To Learn.
Thank You For All.
Thank you all for assistance. Post#8 worked.
msquared's solution post#6 was interesting too.
And yes thanks ahmedtharwat19 for the attachment(post#7).
Thanks all.
I am happy to be part of this genius community. Much Regards Sign in to post your reply or Sign up for a free account.
Similar topics
by: jj |
last post by:
Hi All
I wan't to create a PDF document automatically from Access, and I have tried
to use the way Keri Hardwick explains on:
http://www.mvps.org/access/reports/rpt0011.htm
But when the code...
|
by: Robert McGregor |
last post by:
Using the follwing code and getting the error message:
Run time error '2455':
You entered an expression that contains an invalid reference to the
property MaxRecButton.
My code just...
|
by: SheldonMopes |
last post by:
I have a command button on a form that changes the filter and order
conditions on a subform (the subform is based on a query). Sometimes,
if I click the button again immediately after clicking on...
|
by: Crayola465 |
last post by:
I have been trying to figure this out for a couple weeks and after reading every post in the forum about the subject I have not found anything that works.
I have two tables;
1) has company...
|
by: Asle |
last post by:
Hi,
I have a form called Customer and another form called Loan..
the Loan Details has to be entered every month until it is closed.
I have designed a form such that, the user goes to the...
|
by: JFKJr |
last post by:
HI!, I am trying to import an excel file to an Access table using the following code, but I am getting "Run-time error '31519':You cannot import this file" error.
Function Import_ExcelFile()...
|
by: dee |
last post by:
I have a form 'FmMessages" and a form 'FmLeads'.
'FmMessages', through code, opens 'FmMessages" if it is not already
open.
It then sets focus on 'FmLeads' and runs the following code:
Dim rst...
|
by: Sep410 |
last post by:
Hi all,
Here is my code:
Private Sub Command12_Click()
Dim strSql As String
strSql = "Delete from tbl_city where CityId=" & Val(Me!txtEmail.Text) & ";"
Set cn =...
|
by: ramprat |
last post by:
Hi
Sorry to keep asking questions but I keep getting a run-time error 2001 "you canceled the previous operation" error whenever the code in the Dlookup line is reached. I have a table called...
|
by: mufc4life |
last post by:
Hi, actually I'm creating a database for some coursework at school. It's basically about a booking system and how I book hardware in and out of the school for students who need the hardware. I've...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |