Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

My Cancel Button Is Not Working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Norris - 13 Apr 2005 19:12 GMT
My cancel button is not working.  It's opening my add form even if I click
on the cancel button.  Below is my code.  Thanks in advance for any
suggestions......

Private Sub AddNewRcd_Click()
On Error GoTo Err_AddNewRcd_Click
If MsgBox("Are you sure you want to ADD A New Record? ", vbOKCancel) <>
vbOK Then
      Cancel = True
              End If
DoCmd.OpenForm "frmProfileAdd2"
   DoCmd.GoToRecord , , acNewRec

Exit_AddNewRcd_Click:
   Exit Sub

Err_AddNewRcd_Click:
   MsgBox "ADD Canceled" 'Err.DescriptionErr.Description
   Resume Exit_AddNewRcd_Click
End Sub
Steve Norris - 13 Apr 2005 19:19 GMT
Ok, I got it to work.  Here's the revised code.....

Private Sub AddNewRcd_Click()
On Error GoTo Err_AddNewRcd_Click
If MsgBox("Are you sure you want to ADD A New Record? ", vbOKCancel) <>
vbOK Then
      Cancel = True
            'Me.Undo
       DoCmd.CancelEvent
       MsgBox "ADD Record Canceled"
   Else
   DoCmd.OpenForm "frmProfileAdd2"
   DoCmd.GoToRecord , , acNewRec
   
         End If

Exit_AddNewRcd_Click:
   Exit Sub

Err_AddNewRcd_Click:
   MsgBox "ADD Canceled" 'Err.DescriptionErr.Description
   Resume Exit_AddNewRcd_Click
End Sub
Dirk Goldgar - 13 Apr 2005 20:20 GMT
> Ok, I got it to work.  Here's the revised code.....
>
[quoted text clipped - 19 lines]
>     Resume Exit_AddNewRcd_Click
> End Sub

No need for *both*

>        Cancel = True

and

>         DoCmd.CancelEvent

Delete the "DoCmd.CancelEvent" line, since it's not doing anything.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Douglas J. Steele - 13 Apr 2005 21:11 GMT
>> Ok, I got it to work.  Here's the revised code.....
>>
[quoted text clipped - 29 lines]
>
> Delete the "DoCmd.CancelEvent" line, since it's not doing anything.

Isn't it the Cancel = True that he should delete? It's not like this is a
BeforeUpdate event, where setting Cancel = True will undo the update. (For
that matter, I have to assume that he's either declared Cancel as a
module-level variable, or else he's running without Option Explicit turned
on, since Cancel isn't declared anywhere in the module)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


Dirk Goldgar - 13 Apr 2005 21:42 GMT
>> Delete the "DoCmd.CancelEvent" line, since it's not doing anything.
>
[quoted text clipped - 4 lines]
> Option Explicit turned on, since Cancel isn't declared anywhere in
> the module)

Duh.  You're right, of course.  Probably neither of those "cancel"
statements accomplishes anything.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Steve Norris - 13 Apr 2005 22:06 GMT
You are both correct.  I removed both cancels from my routine and it still
works.

Thanks a bunch for a better understanding of the option explicit too!

Steve
Justin Hoffman - 13 Apr 2005 21:01 GMT
> My cancel button is not working.  It's opening my add form even if I click
> on the cancel button.  Below is my code.  Thanks in advance for any
[quoted text clipped - 16 lines]
>    Resume Exit_AddNewRcd_Click
> End Sub

I cannot see where Cancel comes from.  Where is it defined?  While looking
at your code, select Compile from the Debug menu.  Does it compile?  It
should not if you use 'Option Explicit' which forces you to declare
variables.  If you don't, then you could write whatever you like Cancel=True
or Banana=True or Silly=True.  They all do the same thing: nothing.
If you just need a quick fix, then simply changing the line
Cancel=True
to
Exit Sub
would solve this immediate problem.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.