By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,162 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,162 IT Pros & Developers. It's quick & easy.

Checkbox problem

P: 52
I have amessage box that is used when a user clicks on a checkbox. if the user hits cancel, all of the other checkboxes dont work (when i click them, nothing happens) but if the user hits ok instaed, everything works fine. Any ideas?
Dec 11 '07 #1
Share this Question
Share on Google+
14 Replies


lee123
100+
P: 556
what does the code look like in you checkbox?

lee123
Dec 11 '07 #2

P: 52
Sure, Thank you:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkMon_AfterUpdate()
  2.  
  3.     If chkMon.Value = -1 Then txtMon.Value = "MO" Else txtMon.Value = Null
  4.  
  5.     If IsNull(Me.Mon) And Not IsNull(Me.txtMon) Then
  6.         Response = MsgBox("MONDAY is not an approved day." & vbCrLf & "Do you want to continue?", vbOKCancel + vbExclamation, "Customer Schedule Conflict")
  7.     End If
  8.  
  9.     If Response = 2 Then
  10.         Me.chkMon.Value = 0
  11.         Me.txtMon.Value = Null
  12.     ElseIf Response = 1 Then
  13.         Me.txtOveride.Value = Format(Now(), "mm/dd/yyyy")
  14.     End If
Dec 11 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
You don't show the entire Sub procedure, but the code you do show has unmatched If...End Ifs. You may have another End If you didn't show, and hence have matching If...End Ifs, but I think they're in the wrong places. This line

Expand|Select|Wrap|Line Numbers
  1. If chkMon.Value = -1 Then txtMon.Value = "MO" Else txtMon.Value = Null
  2.  
needs to be

Expand|Select|Wrap|Line Numbers
  1. If chkMon.Value = -1 Then 
  2.    txtMon.Value = "MO"
  3. Else
  4. txtMon.Value = Null
  5. End If
You can have a single line like
Expand|Select|Wrap|Line Numbers
  1. If chkMon.Value = -1 Then txtMon.Value = "MO" 
without a closing End If, but not an If...Else... on a single line without and End If.

Mismatched If...End Ifs cause many strange things, so try correcting this and see what happens.

Linq ;0)>
Dec 11 '07 #4

P: 52
Thanks, i tried to re-write the If statement and i am having the same problem.
Dec 12 '07 #5

missinglinq
Expert 2.5K+
P: 3,532
Don't know what to tell you. The change I suggested needed to be done, but I was afraid it wouldn't solve things. The problem is that none of the code you've posted has anything to do with any checkboxes other than thechkMon. I guess we need to be able to actually look under the hood of your database, if you could zip it up and post it here.

BTW, what is the object Me.Mon referring to in

If IsNull(Me.Mon) And Not IsNull(Me.txtMon) Then

Linq ;0)>
Dec 12 '07 #6

P: 52
This is killing me. I couldnt attach a file, it was too big so the link to the file is below. if you could take a look at it i would really appreciate it.

http://www.imperialelevatorcorp.com/...d/checkbox.zip
Dec 12 '07 #7

missinglinq
Expert 2.5K+
P: 3,532
I'll have to look at this in depth later today when I get some time, and try to figure out exactly what you're trying to do.

Right off hand I see one problem in that your Time Period Option Group isn't bound to your underlying table. This means if you enter a new patient, select, say, Permanent and pick the desired days, then go to another record and come back to the new patient to change days, you've got to select Permanent again to enable your check boxes. When you return to an existing record, the checkboxes should be enabled/disabled depending on the value in the Option Group; you shouldn't have to go thru the process again and this requires that the Time Period select be a part of each record.

What I can't reproduce is the problem you've stated! If I enter a new record, click on Permanent or Multiple Days, select chkMon, the messagebox comes up and I hit Cancel, the checkboxes are still enabled! Is there anything you can add to help me figure out what's going wrong for you? Maybe give me a step by step of what you're doing that's leading up to the problem?

Linq ;0)>
Dec 12 '07 #8

P: 52
Thank you again.When i pull up the first recor "Leon Lantsman" and select either "permanent" or "multiple days" and select SAT, after hitting cancel, all the checkboxes are enabled but i cant check off su, mon, tue, wed, thur, fri. i have tried on other machines, and i get the same problem.
Dec 12 '07 #9

missinglinq
Expert 2.5K+
P: 3,532
I've got to tell you this thing has been driving me crazy! I actually dreamnt about it last night and woke up this morning with the answer! I really don't even understand why this was causing the particular problem, but it solves it!

At the top of your code module you have this statement

Option Explicit

From Access Help:
"When Option Explicit appears in a module, you must explicitly declare all variables using the Dim, Private, Public, ReDim, or Static statements."

The problem is that you didn't do this for the variable (Response) that you use to hold the user's choice from your messagebox! You need to redo the AfterUpdates for all of your checkboxes to add this single line:

Dim Response As Integer


at the beginning of each sub, as it appears here in Line # 2.
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkMon_AfterUpdate()
  2. Dim Response As Integer
  3.  
  4.     If Me.chkMon.Value = -1 Then
  5.         Me.txtMon.Value = "MO"
  6.     Else
  7.         Me.txtMon.Value = Null
  8.     End If
  9.  
  10.     If IsNull(Me.Mon) And Not IsNull(Me.txtMon) Then
  11. Response = MsgBox("MONDAY is not an approved day." & vbCrLf & "Do you want to continue?", vbOKCancel + vbExclamation, "Customer Schedule Conflict")
  12.     End If
  13.  
  14.     If Response = 2 Then
  15.         Me.chkMon.Value = 0
  16.         Me.txtMon.Value = Null
  17.     ElseIf Response = 1 Then
  18.         Me.txtOveride.Value = Format(Now(), "mm/dd/yyyy")
  19.  
  20.     End If
  21.  
  22. End Sub
  23.  
You've also got some other, non-related issues that I noticed in looking under the hood of your app. First, in this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.     DoCmd.GoToRecord , , acNewRec
  4.  
  5. Me.chkSat.Enabled = False
  6. Me.chkSun.Enabled = False
  7. Me.chkMon.Enabled = False
  8. Me.chkTue.Enabled = False
  9. Me.chkWed.Enabled = False
  10. Me.chkThur.Enabled = False
  11. Me.chkFri.Enabled = False
  12.  
  13.     Me.txtStartDate.Value = Null
  14.     Me.txtEndDate.Value = Null
  15.  
  16.     Me.txtStartDate.Visible = False
  17.     Me.txtEndDate.Visible = False
  18.  
  19. End Sub
why do you have all the checkboxes disabled here when you already have them disabled in the Properties Box in Design View? I don't think it it really causes any problems to disable them twice, but I'm concerned that you may think it's doing something here that it's not!

And secondly, go to your dropdown box, select Sara Lantsman, and see whose record pops up!

After you get your code modified to include the

Dim Response As Integer

statement and make sure this is performing as you wanted, post back and we'll address the other issues.

Linq ;0)>
Dec 13 '07 #10

NeoPa
Expert Mod 15k+
P: 31,660
With all those nubile (and semi-dressed) pop-stars and actresses to dream of - you dream of a database!
You neeeeed help my friend :D
Dec 13 '07 #11

missinglinq
Expert 2.5K+
P: 3,532
Sad but true, Ade! Actually, I've dreamed code since I first started writing it, years ago in Basic! Some of my best hacks came to me that way, including how to program a relational database in Basic! Of course, I didn't actually know that it was a relational database; this was back before Access and DB5 and such were invented! I just knew it kept me from entering the same data over and over again!

Linq ;0)>
Dec 13 '07 #12

missinglinq
Expert 2.5K+
P: 3,532
darnnnel, since we've solved your original problem, I'm going to split off the new problem into a separate thread located at Combobox always retrieves the first client when multiple clients have same last name. It's a problem that comes up from time to time, and this way we can give it a more descriptive name which may help others that come searching!

Linq ;0)>
Dec 13 '07 #13

P: 52
Thanks, really appreciate it.
Dec 13 '07 #14

NeoPa
Expert Mod 15k+
P: 31,660
Sad but true, Ade! Actually, I've dreamed code since I first started writing it, years ago in Basic! Some of my best hacks came to me that way, including how to program a relational database in Basic! Of course, I didn't actually know that it was a relational database; this was back before Access and DB5 and such were invented! I just knew it kept me from entering the same data over and over again!

Linq ;0)>
It's called inspiration. Where would we be without it.
Dec 13 '07 #15

Post your reply

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