Checkbox undo-problem!

  • Thread starter Thread starter Niklas Östergren
  • Start date Start date
N

Niklas Östergren

Hi!

I have a small problem which I can´t solve! I should be able to do so but I
must have waken up at wrong side today ... ;-)

I need to check if user try to change a checkbox value. If so I need to
validate if the user realy want to change the valu. If not undo the change.

I have tryed this code (see below) in the checkbox BeforeUpdate_Event. But I
get a runtime error 2108 and line "Me.txtParameterDescription.SetFocus" is
marked. The changes are still made.

Any help is apreciated.

TIA!
// Niklas

=====================================
Dim strMsg, strResponse As String ' String to hold Msg to display.

strMsg = "Vill du verkligen ändra värdet?"
strResponse = MsgBox(strMsg, vbYesNo, "Ändra värdet")

If strResponse = vbNo Then
Me.chkUsedParameter.Undo
Me.txtParameterDescription.SetFocus
End If
====================================
 
Regarding the "txtParameterDescription" Control: -

1. Is it on the same Form as the "chkUsedParameter"
Control?
2. Is the "txtParameterDescription" Control enabled?
3. Is the "Tab Stop" Property on
the "txtParameterDescription" Control set to "Yes"?
4. Is the Control name "txtParameterDescription" spelt
correctly in the VB Code?

If the answer to any of the above questions is no, then
therein lies your problem....

HTH


Tony C.
-----Original Message-----
Hi!

I have a small problem which I can´t solve! I should be able to do so but I
must have waken up at wrong side today ... ;-)

I need to check if user try to change a checkbox value. If so I need to
validate if the user realy want to change the valu. If not undo the change.

I have tryed this code (see below) in the checkbox BeforeUpdate_Event. But I
get a runtime error 2108 and
line "Me.txtParameterDescription.SetFocus" is
 
Hi Tony!

Thank´s for your tip. But I´m afraid I have to answer yes to all of them.

1.) Yes "txtParameterDescription" is a control on same form as
"chkUsedParameter".
2.) Yes "txtParameterDescription" is enabled.
3.) Yes "txtParameterDescription" tab stop property is ON.
4.) Yes "txtParameterDescription" is correct spellt in VB Code. I have
checked it several times.

Any more idéas of how to do?

TIA
// Niklas

<[email protected]> skrev i meddelandet
Regarding the "txtParameterDescription" Control: -

1. Is it on the same Form as the "chkUsedParameter"
Control?
2. Is the "txtParameterDescription" Control enabled?
3. Is the "Tab Stop" Property on
the "txtParameterDescription" Control set to "Yes"?
4. Is the Control name "txtParameterDescription" spelt
correctly in the VB Code?

If the answer to any of the above questions is no, then
therein lies your problem....

HTH


Tony C.
-----Original Message-----
Hi!

I have a small problem which I can´t solve! I should be able to do so but I
must have waken up at wrong side today ... ;-)

I need to check if user try to change a checkbox value. If so I need to
validate if the user realy want to change the valu. If not undo the change.

I have tryed this code (see below) in the checkbox BeforeUpdate_Event. But I
get a runtime error 2108 and
line "Me.txtParameterDescription.SetFocus" is
 
Hi!

I have a small problem which I can´t solve! I should be able to do so but I
must have waken up at wrong side today ... ;-)

I need to check if user try to change a checkbox value. If so I need to
validate if the user realy want to change the valu. If not undo the change.

I have tryed this code (see below) in the checkbox BeforeUpdate_Event. But I
get a runtime error 2108 and line "Me.txtParameterDescription.SetFocus" is
marked. The changes are still made.

Any help is apreciated.

TIA!
// Niklas

=====================================
Dim strMsg, strResponse As String ' String to hold Msg to display.

strMsg = "Vill du verkligen ändra värdet?"
strResponse = MsgBox(strMsg, vbYesNo, "Ändra värdet")

If strResponse = vbNo Then
Me.chkUsedParameter.Undo
Me.txtParameterDescription.SetFocus
End If
====================================
The control's BeforeUpdate event has a Cancel argument.

Dim strMsg as String
Dim strResponse as integer '***
strMsg = "Vill du verkligen ändra värdet?"
strResponse = MsgBox(strMsg, vbYesNo, "Ändra värdet")

If strResponse = vbNo Then
Cancel = True
End If

It will take you back to the check box with no change made.

*** Note: I followed your usage of strResponse, but vbYesNo returns an
Integer value, not a string. You should use intResponse.

You could tighten up your code to something like this:

If MsgBox("Vill du verkligen ändra värdet?", vbYesNo, "Ändra värdet")
= vbNo Then
Cancel = True
End If
 
You can't change the focus (SetFocus) from the BeforeUpdate event. You can
do it from AfterUpdate.

HTH,
TC
 
Back
Top