Inputbox - Cancel

Sniper-BoOyA-

Registered User.
Local time
Yesterday, 18:06
Joined
Jun 15, 2010
Messages
204
Hey there again,

I have a pretty simple question, just cant find a working solution.

As you might remember i made a function to audit changes. When a change is being made, it checks if the active.control is empty, if it isnt it displays a inputbox to ask for the reason.

Works perfect, but i want to finetune it a little bit, to the point where if the user clicks on cancel (inputbox) it stops the procedure and undo's the change that has been made.

Is this possible, if yes, whats the best approach?

To give you a better idea, this is the VBA code of the function:

Code:
Public Function TrackChanges()
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim strCtl As String
Dim strReason As String
Form_ActivityMonitor.LastAction = Now()
    If Not Screen.ActiveControl.OldValue = Empty Then
        strReason = InputBox("Wat is de reden voor deze wijziging? (Max 40 tekens)")
    End If
        strCtl = Screen.ActiveControl.Name
        strSQL = "SELECT Audit.* FROM Audit;"
        Set db = CurrentDb()
        Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
            If rs.RecordCount > 0 Then rs.MoveLast
             With rs
                 .AddNew
                    rs!FormName = Screen.ActiveForm.Name
                    rs!Veldnaam = strCtl
                    rs!datum = Date
                    rs!Tijd = Time()
                    rs!OudeWaarde = Screen.ActiveControl.OldValue
                    rs!NieuweWaarde = Screen.ActiveControl.Value
                    rs!Gebruiker = fOSUserName
                    rs!LoggedIn = CurrentUser()
                    rs!Computer = FindComputerName
                    rs!Reason = strReason
                .Update
             End With
Set db = Nothing
Set rs = Nothing
End Function
 
Any number of ways, depending on how you want things to flow. This will abort the process:

Code:
        strReason = InputBox("Enter reason driver assigned out of order", "Reason")
        If Len(strReason & vbNullString) = 0 Then
          MsgBox "Driver can not be assigned out of order without a reason"
          GoTo ExitHandler
        End If

        'rest of process here
 

Users who are viewing this thread

Back
Top Bottom