Search code examples
formsms-accessvbacheckoutmsgbox

Microsoft access VBA MsgBox not responding, what am I doing wrong?


so I have put together an asset check out sheet. There is a Check out button, I want a message to prompt " User ID is required" when it is clicked , if the user ID field is left blank . However, that is not the case with my current code, it just accepts the button click no matter what. Am I missing something here ? (code below)

Private Sub CHECK_OUT_BUTTON_Click()
    If (IsNull(Me.USER_ID)) Then
        MsgBox "User ID is required."
    Else
        If Me.Status.Value = "Checked Out" Then
           MsgBox "This device is currently in use."
        Else
            If (Me.Status.Value = "Available") And (Not IsNull(Me.USER_ID)) Then
                Me.Status.Value = "Checked Out"
                RunCommand acCmdSaveRecord
                Me.Requery
            End If
        End If
    End If
End Sub

Solution

  • Looks like the User ID field was not registering as NULL and was instead just an empty string.

    Changing the line:

    If(IsNull(Me.USER_ID)) Then

    To:

    If(Nz(Me!USER_ID.Value) = "") Then

    Should catch empty User IDs