Inputbox

Spikenaylor

Board Regular
Joined
Apr 14, 2013
Messages
116
Office Version
  1. 365
Platform
  1. Windows
I have tried unsuccessfully to achieve this

Display Input box "Please enter a reason"

If the X or Cancel is pressed the the routine ends

If OK is pressed and the input contains nothing, then display a message "Reason is required"

I cant seem to get this combination to work correctly

Code:
Sub AuditTrail(batchnumber As String)
Dim batchunlock as boolean, batchunlockmessage as string
On Error Resume Next
Recheck:
    batchunlock = Application.InputBox("Please enter the reason you are cancelling the Batch", "Cancelling Batch Reason")
    batchunlockmessage = batchunlock
    If batchunlock = False Then End
    If batchunlockmessage = vbNullString Then
        MsgBox ("You must enter a reason for cancelling the batch!")
        GoTo Recheck
    End If
On Error GoTo 0
    Sheets("Audit_Trail").Cells(65536, 1).End(xlUp).Offset(1, 0).Value = " Date - " & Date & "          " & " Time - " & Time & "          " & " User - " & Application.UserName & "          Batch number Cancelled - " & batchnumber & "         Reason for Cancelling - " & batchunlockmessage & "          " & " Sheet - " & ActiveSheet.Name


End Sub

I have tried other variants but cannot get the Cancel and X option to be separate from the nothing is entered option.

Any help and guidance greatly appreciated.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
this advice was from another forum but i hope it helps

Code:
Dim response As Variant 
 
response = InputBox("Prompt", "Title") 
Select Case StrPtr(response) 
Case 0 
     'OK not pressed
    Exit Sub 
Case Else 
     'OK pressed
     'Carry on your routine, variable response contains the InputText
End Select
 
Upvote 0
Great thanks, worked great

after seeing that I remember I have seen that before somewhere but have forgotten about it.

Once again
Thanks
 
Upvote 0

Forum statistics

Threads
1,223,276
Messages
6,171,139
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top