473,387 Members | 1,516 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,387 software developers and data experts.

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

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
2 2781
ADezii
8,834 Expert 8TB
@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
32,556 Expert Mod 16PB
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

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

Similar topics

3
by: Roger | last post by:
Hi All, I need to call a text box click event programatically. How would I call the following event procedure from another procedure within the same form: Private Sub TextBox2_Click(ByVal sender...
1
by: gevayl | last post by:
Hi, How does one triger, from a subform event procedure, a main form event procedure? Access 2000 Thanks
0
by: Govindaraj K | last post by:
Hi, I am working with MDI form , In a child form i am unable to move the cursor to previous control using the Shift + Tab combination in KEYDOWN Event procedure. Even i set the tabStop property...
12
by: Adil Akram | last post by:
I want to cancel an event from its event procedure on some condition, I know how to do this in VB6 i.e. by setting cancel=true. Please tell me how can I do this in VB.net I don't know how to use...
3
by: Jason | last post by:
I have an ASP.NET application in which I would like to call my button click event (imgSubmitSearch_Click) on the page load if certain criteria are met. Is this possible? What is the correct...
10
by: jerry.ranch | last post by:
I have a series of comboboxes on a form that are used to display forms in DS view (theres a qry behind it all). This is working well for me. Some people like to see the data in DS view, some in...
1
by: Robert | last post by:
Every thing worked fine until all of a sudden, I get the following error whenever I try to do anything on one of my forms that calls an Event Procedure. I get the error as soon as the form opens...
6
by: MLH | last post by:
I have a form, frmUSPSReturnReceipts, with a control named NotExpectingGreenTickets. The control's Exit event procedure follows: Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer) If...
1
by: AMD_GAMER | last post by:
Hi, I am trying to print address labels. I have a form which asks for the user to input the first name, middle initial, and last name. On the button click to print the label, I have an event...
3
by: grinder332518 | last post by:
My Form accesses a Query as follows : SELECT tblA.A, tblB.B, tblB.C FROM tblA LEFT JOIN tblB ON tblA.A = tblB.A UNION SELECT tblB.A, tblB.B, tblB.C FROM tblB LEFT JOIN TblA ON ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.