PDA

Click to See Complete Forum and Search --> : A cmd_click occurs without clicking.


gvirden
Dec 27th, 1999, 02:47 AM
I don't want employees to check checkbox 3 which will be recorded in the table as a sick pond (actually the fish are sick not the pond) without giving me a count of dead fish first. However, it is possible that the pond can be sick and have no dead fish. So my idea was to throw this message box up to remind employees(if they clicked the sick pond checkbox first, without prior providing a dead fish count) to click an option if they saw dead fish in the pond (this in turn would prompt an inputbox).

Private Sub Check3_Click()
If Check3 = 0 Then
Exit Sub
End If
MsgBox ("If there are any dead fish in " & lblpond & ", uncheck this box " & _
"and click yes above in-- Any dead fish floating?"), , "Warning! Report Dead Fish"
End Sub

Well they click OK to the msgbox, because they forgot to give me a count, and they must also unclick check3 for the next event to work. Of course the next event is to click yes to option25 (please don't make fun of that number) which means they see dead fish floating in the pond. When option25 is enabled (clicked), the floatingfish table opens and so on...

With rs
.AddNew
!pond = lblpond
!Date = Date
!By = strBy
Do Until Check3 = 1
deadfish = InputBox("Please estimate the number of dead fish.")
If IsNumeric(deadfish) And deadfish > 0 And deadfish < 100001 Then
Check3 = 1
Else: MsgBox ("Please enter a number between 1 and 100,000"), , "Try Again"
End If
Loop
!Number = deadfish
.Update
End With

This enters a complete record into my table floatingfish (that doesn't sound too morbid does it?). Anyway, this works great! The problem is that that message box comes back up again. Why does it do that. I'm telling VB to give me that msgbox on check3_click(). No where I am saying if check3 = 1 then msgbox(etc).

JohnAtWork
Dec 27th, 1999, 03:46 AM
When you say the MsgBox comes up again, when does it reappear?

After they deselect box 3, or in the second routine where you set ChkBox = 1?

gvirden
Dec 27th, 1999, 04:04 AM
In the second routine.

It was coming back up when I went back and deselect check3 so I put in

If Check3 = 0 Then
Exit Sub

after Private Sub Check3_Click(). That killed that msgbox.

Clunietp
Dec 27th, 1999, 09:43 AM
I'm not sure if you said you got it figured out, but when you manually assign Check3 = 1, the Check3_Click event will still fire, even though the user did not actually click on the checkbox.

Otherwise, you may want to change your event to Check3_MouseUp instead of Check3_Click so that event will not be fired by your code.

Also, if you have named your controls option1, option2, option3, etc.... and you have to go back and modify this app 6 months down the road, you will want to hang yourself.

Worse, the poor guy who has to maintain this after you leave the company will want to hunt you down and kick your butt.

Sorry, had to mention it!

Tom

mocoo
Dec 27th, 1999, 02:32 PM
If you want to check for something before actually checking the box, I'd use the Mouse_Down event for the check box. And once everything meets your requirements, you can call the Click event from the Mouse_Down. You have to have a Click event (even empty, with just a comment line) for this to work. If you decide you don't want to check the checkbox, you don't call the Click event, and nothing will happen.
Hope this helps.
Mocoo

Clunietp
Dec 27th, 1999, 10:24 PM
That is a better idea, mocoo, thank you!

Instead of calling a click event, he could just use Check3 = 1 in the Check3_MouseDown so he won't have to worry about coding another event.


MORAL of this story:

If you want to validate BEFORE the user clicks on a checkbox, use the mousedown.

If you want to validate AFTER the user clicks on a checkbox, use the mouseup.

[This message has been edited by Clunietp (edited 12-28-1999).]

gvirden
Dec 28th, 1999, 12:19 AM
Sorry, not checkboxes in a field, I mean a frame.

gvirden
Dec 28th, 1999, 11:07 AM
Great input, thanks!

You know, I really didn't need anything but check3 to collect the input. Like this--

Private Sub Check3_click()
getreason
intresponse = MsgBox("See any dead fish?", 4, "Warning, report all dead fish!")
If intresponse = vbYes Then
'enters a new record into the floatingfish table....

With rs
.AddNew
!pond = lblpond
!Date = Date
!By = strBy
Do Until x
deadfish = InputBox("Please estimate the number of dead fish.")
If IsNumeric(deadfish) And deadfish > 0 And deadfish < 100001 Then
x = deadfish
Else: MsgBox ("Please enter a number between 1 and 100,000"), , "Try Again"
End If
Loop
!Number = deadfish
.Update
End With
Else:
Exit Sub
End If
End Sub

I really wanted to stay away from the mouse because the user input environment (riding around in a pickup on the farm) was not conducive to it. This brings me to another problem with check boxes in a field. I would like use a shortcut key to get to the field, use the tab to move, and use enter to check the box. Can I do this programmably?

Clunietp
Dec 28th, 1999, 11:44 AM
Tab will move the focus control by control (depends how you have your TabIndexes) and the space bar will act as the 'action' key for that control. Press the space bar when a command button has focus, the button will be clicked. Press the space bar when a checkbox has the focus, the check will appear/disappear

HTH

Tom

Gerald
Dec 29th, 1999, 11:45 AM
You can create a hot key (Alt+key) by using an ampersand character within the caption of you checkbox control. For example if you set your checkbox caption to "Any &dead fish floating?", pressing Alt+D would set the input focus to your checkbox.

Gerald