+ Reply to Thread
Results 1 to 4 of 4

Canceling on Input Box

Hybrid View

  1. #1
    Registered User
    Join Date
    03-11-2019
    Location
    Woodland Hills
    MS-Off Ver
    2016
    Posts
    2

    Canceling on Input Box

    Hi All,

    i don't know anything about VBA, but I was able to locate a VBA script that works to fit my needs. The only thing that does not work is the "Cancel' button that populates on the Input boxes. Can someone help me fill in the gap for this?

    ----------
    Sub AZ_Monthly()
    
    Dim cvsApp As Object
    Dim cvsConn As Object
    Dim cvsSrv As Object
    Dim Rep As Object
    Dim Info As Object, Log As Object, b As Object
    Dim CMSRunning As String
    Dim objWMIcimv2 As Object
    Dim objProcess As Object
    Dim objList As Object
    
    CMSRunning = "acsSRV.exe"
    
    Set objWMIcimv2 = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace
    
    Set objList = objWMIcimv2.ExecQuery _
    ("select * from win32_process where name='" & CMSRunning & "'") 'determine if CMS is running
    
    If objList.Count = 0 Then 'If 0 then process isn't running
    
    End If
    
    Set cvsApp = CreateObject("ACSUP.cvsApplication")
    Set cvsConn = CreateObject("ACSCN.cvsConnection")
    Set cvsSrv = CreateObject("ACSUPSRV.cvsServer")
    Set Rep = CreateObject("ACSREP.cvsReport")
    
    Application.ScreenUpdating = 0
    
    Set cvsSrv = cvsApp.Servers(1)
    Application.ScreenUpdating = 1
    
    AgGrp = InputBox("Enter Agent Group Name", "Agent Group", "Medicare BSU AZ") 'change as needed for variables to enter into report
    RpDate = InputBox("Enter Date", "Date", "XX/XX/XXXX-XX/XX/XXXX") 'change as needed for variables to enter into report
    
    'Start code from CMS Export script
    On Error Resume Next
    
    cvsSrv.Reports.ACD = 2
    Set Info = cvsSrv.Reports.Reports("Historical\Designer\Medicare BSU Metrics")
    
    b = cvsSrv.Reports.CreateReport(Info, Rep)
    If b Then
    
    Rep.Window.Top = 1830
    Rep.Window.Left = 975
    Rep.Window.Width = 17610
    Rep.Window.Height = 11910
    
    Rep.SetProperty "Agent Group", AgGrp 'change as needed for report variables
    
    Rep.SetProperty "Dates", RpDate 'change as needed for report variables
    Rep.TimeZone = "default"
    b = Rep.ExportData("", 9, 0, True, True, True)
    Rep.Quit
    
    If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
    Set Rep = Nothing
    End If
    
    Set Info = Nothing
    
    ' End code from CMS Export Script
    
    cvsConn.logout
    cvsConn.Disconnect
    cvsSrv.Connected = False
    Set Log = Nothing
    Set Rep = Nothing
    Set cvsSrv = Nothing
    Set cvsConn = Nothing
    Set cvsApp = Nothing
    Set Info = Nothing
    
        Range("Z53").Select
        ActiveSheet.Paste
        
        End Sub
    Last edited by jeffreybrown; 03-11-2019 at 05:53 PM. Reason: Please use code tags when posting code!

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,494

    Re: Canceling on Input Box

    After the code for the inputboxes put statements like this
    you did not say what you want to happen if cancel is used. so I build to options.

    The first line of AgGrp will stop executing the rest of the macro if cancel is pressed.
    The second line for RpDate will use the last day of last month as reporting date and continue the macro with that date

    If AgGrp = vbNullString Then Exit Sub
    If Rpdate = vbNullString Then Rpdate = DateSerial(Year(Date), Month(Date), 0)
    so it is up to you if that is suitable or that you need other things to happen when cancel is used.

  3. #3
    Registered User
    Join Date
    03-11-2019
    Location
    Woodland Hills
    MS-Off Ver
    2016
    Posts
    2

    Re: Canceling on Input Box

    You da man Roel!

    Thank you Very much.

    Thanks, Keebellah!

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Canceling on Input Box

    Hi, welcome to the forum.
    If I understand you correctly you need to test if the user entered something of pressed Cancel?

    You will need to add two tests
    Firt one is check if AgGrp has been entered

    First Dimension ALL your variables

    Dim AgGrp As Variant
    Dim RpDate As Variant
    AgGrp = InputBox("Enter Agent Group Name", "Agent Group", "Medicare BSU AZ") 'change as needed for variables to enter into report
    
    If VarType(AgGrp) = vbBoolean then exit sub
    
    RpDate = InputBox("Enter Date", "Date", "XX/XX/XXXX-XX/XX/XXXX") 'change as needed for variables to enter into report
    
    If VarType(RpDate) = vbBoolean then exit sub
    What this does is check if anything has been entered, if the user presses X (top right) then it's Canceled and the value is FALSE and this a Boolean (True or False)

    If tha type of answer is a Boolean the it's false so it exist the sub

    Hope this helps
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] conditional self canceling macro
    By gt4udish in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2015, 06:56 PM
  2. Canceling a Print Job
    By EdWoods in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-14-2013, 08:02 PM
  3. canceling sorting function
    By Vogelmann in forum Excel General
    Replies: 2
    Last Post: 10-24-2012, 07:49 AM
  4. BeforeClose Event - MsgBox Yes No - is not canceling
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-03-2012, 11:51 AM
  5. Loop in canceling of event
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-30-2011, 07:14 PM
  6. Canceling out zeros
    By esupply in forum Excel General
    Replies: 5
    Last Post: 03-12-2010, 05:07 PM
  7. Canceling items from a sheet
    By Skiman in forum Excel General
    Replies: 9
    Last Post: 03-02-2008, 09:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1