+ Reply to Thread
Results 1 to 4 of 4

activate cancel button in a inputbox

Hybrid View

mania112 activate cancel button in a... 10-19-2009, 05:52 AM
Richard Buttrey Re: activate cancel button in... 10-19-2009, 06:20 AM
mania112 Re: activate cancel button in... 10-19-2009, 07:08 AM
royUK Re: activate cancel button in... 10-19-2009, 07:09 AM
  1. #1
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    99

    activate cancel button in a inputbox

    in vb, i have the following code to enter clients details, which works fine:

    Sub NewUpdate()
    
        Dim DateRec As Date
        Dim ClientRef As String
        Dim ClientForename As String
        Dim ClientSurname As String
        Dim ClientEmail As String
        Dim NoOfPols As Integer
        Dim Polcount As Integer
        Dim Policies(1 To 9) As String
        Dim InsRow As Integer
        Dim DestCell As Integer
        
        
        DateRec = InputBox("Enter Date Factfind received (DD/MM/YY)", "Date Received")
        ClientRef = InputBox("Enter Client reference code", "Client RefCode")
        ClientForename = InputBox("Enter Client Forename", "Client Forename")
        ClientSurname = InputBox("Enter Client Surname", "Client Surname")
        ClientEmail = InputBox("Enter Client Email address", "Client Email")
        InsRow = 16
        DestCell = 15
        
        NoOfPols = InputBox("How many policies?", "No Of Pols")
        
        Polcount = NoOfPols
        
        Do While Polcount > 0
            Policies(Polcount) = InputBox("Policy Name", "Policy Name")
            Polcount = Polcount - 1
        Loop
        
        Sheets("#Template - do not delete").Select
        Sheets("#Template - do not delete").Copy After:=Sheets("#Template - do not delete")
        Sheets("#Template - do not delete (2)").Name = ClientRef
        Sheets(ClientRef).Range("F12").Value = DateRec
        Sheets(ClientRef).Range("C1").Value = ClientEmail
        Sheets(ClientRef).Range("C1").Font.Color = RGB(255, 255, 255)
        Sheets(ClientRef).Range("A8,F8").Value = ClientRef & " - Case Progression"
        
        Polcount = NoOfPols
        
        Do While Polcount > 0
            Sheets(ClientRef).Range("C" & DestCell).Value = Policies(Polcount)
            Polcount = Polcount - 1
            If Polcount > 0 Then
                Range("A" & InsRow).Select
                Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
                InsRow = InsRow + 1
                DestCell = DestCell + 1
            End If
        Loop
        
        Sheets("#Client List").Range("A200").Value = ClientSurname
        Sheets("#Client List").Range("B200").Value = ClientForename
        Sheets("#Client List").Range("C200").Value = ClientRef
        Sheets("#Client List").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Range("A200"), Address:="", SubAddress:= _
            ClientRef & "!A1", TextToDisplay:=ClientSurname
        Call SortAlpha
        Call SortWorksheets
    We have some new staff starting next week, so i wanted to tidy a few things up, namely when you 'add new client' the inputbox appears, but at the moment if you hit cancel the code chokes and the usual vb runtime error appears.

    all i wanted therefore is an idea of how to apply a line or two to allow the user to cleanly cancel and return to the 'client list' sheet.

    i'm sure this is quite simple, i just hope it doesnt need a complete overhaul of the way this code's written.

    many thanks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: activate cancel button in a inputbox

    Hi,

    
    On Error Resume Next
    DateRec = InputBox("Enter Date Factfind received (DD/MM/YY)", "Date Received")
    If Err.Number = 13 Then Exit Sub
    on Error Goto 0
    Incidentally provided the user always enters dates in the ddmmyy format you will be OK, but you might want to consider what would happen if a US user say entered mmddyy. You might like to consider capturing the day, date and month in separate listboxes which contain days 1-31, months January - December and Year numbers. Then you can build the Date variable by using the DateSerial() instruction.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    99

    Re: activate cancel button in a inputbox

    thanks, that worked great.

    I have another problem while doing this 'tidy up'

    i'll have to start a new thread on it, for some reason i cannot get to the manage attachments pane, hoping a new thread will solve the problem

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: activate cancel button in a inputbox

    Quote Originally Posted by mania112 View Post
    thanks, that worked great.

    I have another problem while doing this 'tidy up'

    i'll have to start a new thread on it, for some reason i cannot get to the manage attachments pane, hoping a new thread will solve the problem
    You should start a new Thread for additional questions, add a link to this one if i might help.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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