Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Undo method?

Status
Not open for further replies.

fredzeppelin

Technical User
Mar 17, 2005
26
US
I have a text box, which I want to allow changes, but with a strong warning to be sure. Proc tied to BeforeUpdate event:

Stolen straight from the Access doc's/examples.

Code:
Private Sub Text39_BeforeUpdate(Cancel As Integer)
 
  Dim strMsg As String
  strMsg = "Don't Do It !"
   
  If MsgBox(strMsg, vbExclamation + vbOKCancel, "Are You Sure?") = vbOK Then

     Cancel = False
  Else
     Cancel = True
     Me!Text39.Undo
End If


If I click OK, the textbox stays changed, and the cursor moves on to whatever I did to trigger the control update (eg TAB).

If I click Cancel the Text in the TexBox is selected (highlighted)and the cursor is positioned at chr(0).

I'd hoped that the text would be returned to its pre-edit state and the cursor would do something useful and predicatable based on the update triggering event.

I'm not sure I understand what Cancel and Undo do in this context, and if there's any interaction between them.

I searched the fora and faq's, didn't see anything. If one exists, just point.

(I assume that a Boolean type is just an Integer which is only permitted two values;
0 and -1 ?
Cancel as Integer = True ' hmmmmmmm?
Then the real propellor heads can play all those bit-manipulation games )

Thanks
 
Nicked straight from Access created VBA

Code:
Private Sub cmdUndo_Click()
On Error GoTo Err_cmdUndo_Click
    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Exit_cmdUndo_Click:
    Exit Sub
Err_cmdUndo_Click:
    MsgBox Err.Description
    Resume Exit_cmdUndo_Click
End Sub

The undo bit is the DoCmd.DoMenuItem ... etc bit



Program Error
Why is it, I still think in terms of spectrum BASIC!
 
If you click ok, shouldn't Cancel be True and Else be False?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top