Results 1 to 8 of 8

Message Box Cancel Button

  1. #1
    keith701a is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    15

    Message Box Cancel Button


    I have a button that opens a message box with an "on click" event:

    Dim strInput As String
    strInput = InputBox("Enter Report Number")
    DoCmd.OpenForm "Update_Form", , , "Report_Number = '" & strInput & "'


    The user inputs a report number and clicks okay to open "Update_Form" filtered by said report number. If cancel is clicked "Update_Form" still opens, but blank.

    I would like "Update_Form" to not open and to browse to a form named "HOME" if cancel is clicked. Is there a way to build this into the code?

  2. #2
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    Try:

    Code:
    Dim strInput As String
    strInput = If MsgBox("This will erase everything, are you sure?", vbOKCancel) = vbOK Then InputBox("Enter Report Number")
    If strInPut = vbNullString Then
            MsgBox ("User canceled!")
    Else
    DoCmd.OpenForm "Update_Form", , , "Report_Number = '" & strInput & "'
    End If
    Last edited by AccessPower; 02-07-2017 at 07:10 AM.

  3. #3
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    699
    I prefer to collect data using a form. This allows you to use controls, like a combo box, to look up data. You can also do some data validation before moving on.

    I would test to see that the input box retirned and data before opening the form.

    Try:

    Code:
    Dim strInput As String
    strInput = InputBox("Enter Report Number")
    
    if strInput > "" Then 
        DoCmd.OpenForm "Update_Form", , , "Report_Number = '" & strInput & "'
    End If

  4. #4
    jessie0642 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    3
    2015 Q1 c
    =Format(Now(),"dddd dd mmmm hh:nn")
    2015 Q2 a
    [Forms]![Programme]![ProgrammeName] Like "*S*" And [Forms]![Station]![StationName] Like "*1" And Format([Forms]![Airing_Stats]![DateTIme],"dddd") In ("Tuesday","Thursday")
    2015 Q3 a
    Option Compare Database
    Private Sub Val3_Exit(Cancel As Integer)
    MsgBox ("average length is " & ((Len(Val1)) + (Len(Val2)) + (Len(Val3))) / 3)
    End Sub

    2015 Q3 b

    Option Compare Database
    Public Function convertme(NumberVal As Integer, ConversionType As String)
    If ConversionType = "temperature" Then
    MsgBox (NumberVal & " fahrenheit is " & (NumberVal - 32) * 5 / 9 & " Celsius")
    End If
    If ConversionType = "distance" Then
    MsgBox (NumberVal & " miles are " & NumberVal / 0.62137 & " KMs")
    End If
    If ConversionType = "weight" Then
    MsgBox (NumberVal & " MLs are " & NumberVal / 0.0338140225589 & " OZs")
    End If
    End Function
    **************************************
    2016 Q2 a
    Format([Forms]![Players]![PlayerDOB],"dddd")="Sunday" And Mid([Forms]![Teams]![TEAMNAME],2,1)="E" And [Forms]![Players]![GoalsScored] Mod 2<>0
    2016 q2 B
    MessageBox
    ="PLAYERS IS " & DateDiff("yyyy",[Forms]![players]![PlayerDOB],Date())
    2016 a3 a
    Option Compare Database
    Private Sub val2_Exit(Cancel As Integer)
    If val1 > val2 Then
    MsgBox ("Value 1 is the highest")
    ElseIf val2 > val1 Then
    MsgBox ("Value 2 is the highest")
    Else
    MsgBox ("Equal values")
    End If
    End Sub

    2016 q3 b
    Option Compare Database

    Public Function leftover(num1 As Integer, num2 As Integer)
    Dim ans As Integer
    ans = num1 Mod num2
    MsgBox (num1 & " divided by " & num2 & " has a remainder of " & ans)
    End Function
    ************************************************** *******

    2017 q2
    If) DateDiff("yyyy",[Forms]![employees]![hiredate],Date())>20 And [Forms]![employees]![deptname]="Sales"
    Set Value ) [Forms]![employees]![salary]
    [Forms]![employees]![salary]*1.1

    If) DateDiff("yyyy",[Forms]![employees]![hiredate],Date())<20 And DateDiff("yyyy",[Forms]![employees]![hiredate],Date())>=10 And [Forms]![employees]![deptname]="Sales"

    Set value ) [Forms]![employees]![salary]
    [Forms]![employees]![salary]*1.08






    2017 q3
    Option Compare Database

    Public Function TT(val As Integer)
    For outer = val To 1 Step -1
    For inner = 1 To 12
    MsgBox (outer & "*" & inner & "=" & outer * inner)
    Next inner
    Next outer
    End Function

  5. #5
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,006
    I haven't ploughed through your code - partly because you haven't explained why its there.
    Also you haven't code tags which makes it harder to read.

    You've already had 2 good replies explaining how to deal with user cancelling but they forgot to include your HOME form
    Using a slightly modified version of HiTechCoach's code as an example

    Code:
    Dim strInput As String
    strInput = InputBox("Enter Report Number")
    
    if Len(strInput )>0 Then 
        DoCmd.OpenForm "Update_Form", , , "Report_Number = '" & strInput & "' 
    Else
        DoCmd.OpenForm "Home"
    End If
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment
    nil illegitimi carborundum est

  6. #6
    jessie0642 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    3
    test
    dsadsadasd dsadasdas adssadas dasdas

  7. #7
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,006
    Jessie
    I mistakenly thought your first post was by the OP of this thread and hadn't realised it was an old thread
    Now it appears you are just spamming.
    If you have something worth reading, please post it - otherwise, please stop wasting our time
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment
    nil illegitimi carborundum est

  8. #8
    jessie0642 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    3
    okay thanks for advice

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to cancel a loop message box
    By swenger in forum Programming
    Replies: 5
    Last Post: 07-08-2016, 06:12 AM
  2. Cancel button
    By sprtrmp in forum Programming
    Replies: 7
    Last Post: 10-29-2015, 10:50 AM
  3. Cancel Message or Replaced
    By azhar2006 in forum Macros
    Replies: 7
    Last Post: 04-12-2015, 02:20 PM
  4. Y N cancel message box
    By cantord in forum Forms
    Replies: 8
    Last Post: 11-28-2012, 01:20 PM
  5. Yes/No/Cancel Message Box
    By lynnmc26 in forum Access
    Replies: 0
    Last Post: 04-01-2011, 06:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums