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!

Esc vs. command button

Status
Not open for further replies.

debbieg

Technical User
Dec 2, 2002
190
US
Access 2002
Default File Format - Access 2000

I don't understand why this isn't working.

I have a continuous form with the following code:
Code:
Private Sub cmdUndo_Click()
    [green]'to go to the edited record[/green]
    Dim recordnum As Long
    recordnum = Me.CurrentRecord
    DoCmd.GoToRecord , , acGoTo, recordnum
    
    Me.Undo

    Me.cmdClose.SetFocus    
    Me.cmdNext.Visible = True
    Me.cmdPrevious.Visible = True
    Me.cmdSave.Visible = False
    Me.cmdUndo.Visible = False
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyEscape Then cmdUndo_Click
End Sub

My goal is to get back to the current record if they decide not to save their changes and have scrolled.

If I press the ESC key, it goes to the current record.
If I click my Undo button, it does not go to the current record.

Does anyone see what I'm missing?

Debbie
 
Well, I got it to work but I still don't understand why it worked for the ESC key but not my command button.

To get it to work I added

[red]DoCmd.GoToControl CurrentControlName[/red]
DoCmd.GoToRecord , "", acGoTo, recordnum


CurrentControlName is a variable set in my form's module and is set in the each field's On Enter event.

Sorry to bother you,
Debbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top