473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

An event within an event

Hi,
I want to put an event within an event but it seems as though this can't be done and I need to figure a work around. Basically I am trying to say that if the user clicks on the 'cmdRenewTraining' button then it just saves the record without the prompt asking if they wish to save. If they dont press the 'cmdRenewTraining' button then I want the prompt to ask them if they want to save changes. The code looks to make sense but I think the reason Access wont allow it is because it's an event within an event, any ideas how I can get around this problem please? I'm guessing I need to remove lines 2-5 and bring them outside the Private Sub Form_BeforeUpdate(Cancel As Integer)??

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If cmdRenewTraining_Click() Then
  3. DoCmd.Save
  4. End If
  5. Else
  6.  
  7.     If MsgBox("Changes have been made to this record." _
  8.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
  9.         , vbYesNo, "Changes Have Been Made") = vbYes Then
  10.             DoCmd.Save
  11.         Else
  12.             DoCmd.RunCommand acCmdUndo
  13.     End If
  14.     End If
  15. End Sub
Thanks
Apr 18 '08 #1
3 1653
ADezii
8,834 Expert 8TB
Hi,
I want to put an event within an event but it seems as though this can't be done and I need to figure a work around. Basically I am trying to say that if the user clicks on the 'cmdRenewTraining' button then it just saves the record without the prompt asking if they wish to save. If they dont press the 'cmdRenewTraining' button then I want the prompt to ask them if they want to save changes. The code looks to make sense but I think the reason Access wont allow it is because it's an event within an event, any ideas how I can get around this problem please? I'm guessing I need to remove lines 2-5 and bring them outside the Private Sub Form_BeforeUpdate(Cancel As Integer)??

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If cmdRenewTraining_Click() Then
  3. DoCmd.Save
  4. End If
  5. Else
  6.  
  7.     If MsgBox("Changes have been made to this record." _
  8.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
  9.         , vbYesNo, "Changes Have Been Made") = vbYes Then
  10.             DoCmd.Save
  11.         Else
  12.             DoCmd.RunCommand acCmdUndo
  13.     End If
  14.     End If
  15. End Sub
Thanks
  1. First of all, you cannot Save a Record in the BeforeUpdate() Event of a Form.
  2. You can experiment with the following logic, it should be close to what you are requesting:
    1. Declare a Private Variable in the Form's Code Module. The state of this Variable (True/False) will indicate whether or not the cmdRenewTraining button was clicked.
      Expand|Select|Wrap|Line Numbers
      1. Private blnRenewTraining As Boolean
    2. Place the following code in the Click() Event of cmdRenewTraining:
      Expand|Select|Wrap|Line Numbers
      1. Private Sub cmdRenewTraining___Click()
      2.   blnRenewTraining = True       'Indicate the Button was clicked
      3.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
      4. End Sub
    3. Copy and Paste the following code in the BeforeUpdate() Event of the Form. The code will first check and see if the cmdRenewTraining button was clicked and act accordingly:
      Expand|Select|Wrap|Line Numbers
      1. Private Sub Form_BeforeUpdate(Cancel As Integer)
      2. If blnRenewTraining = False Then    'Renew Training Button not clicked
      3.   If MsgBox("Changes have been made to this record." _
      4.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
      5.         , vbYesNo, "Changes Have Been Made") = vbYes Then
      6.   Else
      7.     DoCmd.RunCommand acCmdUndo
      8.   End If
      9. End If
      10. End Sub
    4. Reset our Variable in the AfterUpdate() Event of the Form:
      Expand|Select|Wrap|Line Numbers
      1. Private Sub Form_AfterUpdate()
      2.   blnRenewTraining = False
      3. End Sub
  3. I basically threw this together before bedtime, I'll leave it up to you to determine how well it works. It has obvious drawbacks such as if Required Fields are not filled in prior to repeated Saves, you will continue to get the annoying prompt, etc,
Apr 19 '08 #2
  1. First of all, you cannot Save a Record in the BeforeUpdate() Event of a Form.
  2. You can experiment with the following logic, it should be close to what you are requesting:
    1. Declare a Private Variable in the Form's Code Module. The state of this Variable (True/False) will indicate whether or not the cmdRenewTraining button was clicked.
      Expand|Select|Wrap|Line Numbers
      1. Private blnRenewTraining As Boolean
    2. Place the following code in the Click() Event of cmdRenewTraining:
      Expand|Select|Wrap|Line Numbers
      1. Private Sub cmdRenewTraining___Click()
      2.   blnRenewTraining = True       'Indicate the Button was clicked
      3.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
      4. End Sub
    3. Copy and Paste the following code in the BeforeUpdate() Event of the Form. The code will first check and see if the cmdRenewTraining button was clicked and act accordingly:
      Expand|Select|Wrap|Line Numbers
      1. Private Sub Form_BeforeUpdate(Cancel As Integer)
      2. If blnRenewTraining = False Then    'Renew Training Button not clicked
      3.   If MsgBox("Changes have been made to this record." _
      4.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
      5.         , vbYesNo, "Changes Have Been Made") = vbYes Then
      6.   Else
      7.     DoCmd.RunCommand acCmdUndo
      8.   End If
      9. End If
      10. End Sub
    4. Reset our Variable in the AfterUpdate() Event of the Form:
      Expand|Select|Wrap|Line Numbers
      1. Private Sub Form_AfterUpdate()
      2.   blnRenewTraining = False
      3. End Sub
  3. I basically threw this together before bedtime, I'll leave it up to you to determine how well it works. It has obvious drawbacks such as if Required Fields are not filled in prior to repeated Saves, you will continue to get the annoying prompt, etc,


Thanks very much, it's a good solution to the problem and makes sense. Having made a few tweaks here and there it now works perfectly.

Thanks again
May 1 '08 #3
ADezii
8,834 Expert 8TB
Thanks very much, it's a good solution to the problem and makes sense. Having made a few tweaks here and there it now works perfectly.

Thanks again
You are quite welcome.
May 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
3
by: Marcia Gulesian | last post by:
How can I capture the event when I click (focus) with the cursor anywhere in the page (that is, on a component or elsewhere). This event would occur in an I.E 5.5 or later browser.
6
by: Steve B. | last post by:
Is it good programming practice to call an event within an event? I'm I creating recursion somehow somewhere? Does an event (e.g. send, e) ever end? I'm sorry, I'm not sure I know what I mean,...
1
by: jralford | last post by:
Hi, Another question from a C# newbie: I have a usercontrol class that includes a customized control. Now, if I create an instance of the class, and click on it, a click event is raised for the...
0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
2
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
2
by: Safalra | last post by:
Recently I've rewritten much of my old Javascript code to use DOM functions so that enhancements can be attached to documents without needing to alter the HTML code. I assumed that adding event...
0
by: =?Utf-8?B?Q2xhdWRl?= | last post by:
I start a thread when clicking on a button to synchronize data from within my MainForm. In the threaded method, I fire an event to ask stuff to my controler. When I run the application, it works...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.