Results 1 to 3 of 3
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Vba Help IF STATEMENT

    The following code is to notify the required fields are not left blank.

    If I use the following statement it works fine.


    Private Sub NewEntryBtn_Click()

    If IsNull(Me.ItmBookNo) Then
    MsgBox "Please Enter Book #", vbOKOnly
    Exit Sub
    End If
    DoCmd.GoToRecord , "", acNewRec


    Exit Sub
    If Not IsNull(Me.ItmBookNo) Then
    End If

    End Sub





    I tried the following and is not working.


    Private Sub NewEntryBtn_Click()


    If IsNull(Me.ItmBookNo) Then
    MsgBox "Please Enter Book #", vbOKOnly
    Exit Sub
    End If
    DoCmd.GoToRecord , "", acNewRec


    Exit Sub
    If Not IsNull(Me.ItmBookNo) Then
    End If


    If IsNull(Me.ItemUsedInArea) Then
    MsgBox "Please Enter Area Used At", vbOKOnly
    Exit Sub
    End If
    DoCmd.GoToRecord , "", acNewRec


    Exit Sub
    If Not IsNull(Me.ItemUsedInArea) Then
    End If




    If IsNull(Me.ItmCatagory) Then
    MsgBox "Please Enter Contractor Name", vbOKOnly
    Exit Sub
    End If
    DoCmd.GoToRecord , "", acNewRec


    Exit Sub
    If Not IsNull(Me.ItmCatagory) Then
    End If


    End Sub

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Please post code between code tags (use # button on posting toolbar) to maintain indentation and readability. Harder to follow without it, but I cannot see how you ever expect anything after Exit Sub to run. "Not working" is of zero help to anyone attempting to help you.
    EDIT - BTW, IF blocks like this one do nothing
    Code:
    If Not IsNull(Me.ItmBookNo) Then
    End If
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    273

    Reply

    Code:
    Private Sub NewEntryBtn_Click()
    
      
    If IsNull(Me.ItmBookNo) Then
    MsgBox "Please Enter Book #"
    elseIf IsNull(Me.ItemUsedInArea) Then
    MsgBox "Please Enter Area Used At"
    elseIf IsNull(Me.ItmCatagory) Then
    MsgBox "Please Enter Contractor Name"
    else
    DoCmd.GoToRecord , "", acNewRec
    End If
    End Sub

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

Similar Threads

  1. Replies: 5
    Last Post: 11-01-2021, 08:09 AM
  2. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  3. Iff Statement
    By smc678 in forum Queries
    Replies: 3
    Last Post: 10-10-2013, 11:15 PM
  4. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 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
  •  
Other Forums: Microsoft Office Forums