By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Is is possible to run a Macro & Code in 1 Event Procedure

P: 42
I am attempting to require certain field be populated with data, save the record, and open a new form in one Event procedure when a Comand Button is selected on Form. Unfortunately, this is erroring out on me or halt messages when attempting to run Macro certain intervals.
HAlT Message is Condition=True, Action Name=Close, Arguments Form, frm_CLLDateEntry, prompt


My code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command36_Click()
  2. Dim box As ComboBox
  3. Dim box1 As ComboBox
  4. Dim box2 As ComboBox
  5.  
  6. Set box = Me![LOB]
  7. Set box1 = Me![CALL TYPE]
  8. Set box2 = Me![CALL RESULT]
  9.  
  10. If IsNull(box) Then
  11.   MsgBox "You must select Line of Business", vbExclamation, "No Line of Business"
  12.     box.SetFocus
  13.       box.Dropdown
  14.         Cancel = True
  15. ElseIf IsNull(box1) Then
  16.   MsgBox "You must select Call TYPE", vbExclamation, "No Call Result"
  17.     box1.SetFocus
  18.     box1.Dropdown
  19.       Cancel = True
  20. ElseIf IsNull(box2) Then
  21.   MsgBox "You must select Call Result", vbExclamation, "No Call Type"
  22.     box2.SetFocus
  23.     box2.Dropdown
  24.       Cancel = True
  25. End If
  26.  
  27.     Dim stDocName As String
  28.  
  29.     stDocName = "mcr_AddNew"
  30.     DoCmd.RunMacro stDocName
  31.  
  32. Exit_Command36_Click:
  33.     Exit Sub
  34.  
  35.  
  36. End Sub
Jun 29 '10 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,704
@Bre035
Cancel = True has no meaning within the Context of a Click() Event unless it is defined in the Form's Code Module or Globally in a Standard Code Module. Should this be the case, it is never a good idea to Declare a Boolean Variable named Cancel. You may also wish to Exit the Routine should any NULLs be found in any of the 3 Combo Boxes.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command36_Click()
  2. Dim box As ComboBox
  3. Dim box1 As ComboBox
  4. Dim box2 As ComboBox
  5. Dim stDocName As String
  6.  
  7. Set box = Me![LOB]
  8. Set box1 = Me![CALL TYPE]
  9. Set box2 = Me![CALL RESULT]
  10.  
  11. If IsNull(box) Then
  12.   MsgBox "You must select Line of Business", vbExclamation, "No Line of Business"
  13.     box.SetFocus
  14.       box.Dropdown
  15.         Exit Sub
  16. ElseIf IsNull(box1) Then
  17.   MsgBox "You must select Call TYPE", vbExclamation, "No Call Result"
  18.     box1.SetFocus
  19.       box1.Dropdown
  20.         Exit Sub
  21. ElseIf IsNull(box2) Then
  22.   MsgBox "You must select Call Result", vbExclamation, "No Call Type"
  23.     box2.SetFocus
  24.       box2.Dropdown
  25.         Exit Sub
  26. End If
  27.  
  28. 'Execute only if ALL Combos are polulated
  29. stDocName = "mcr_AddNew"
  30. DoCmd.RunMacro stDocName
  31. End Sub
Jun 29 '10 #2

NeoPa
Expert Mod 15k+
P: 31,769
You can include a macro from within a VBA procedure by simply executing it :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.RunMacro(MacroName, _
  2.                     [RepeatCount], _
  3.                     [RepeatExpression])
Jun 30 '10 #3

Post your reply

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