Results 1 to 4 of 4
  1. #1
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57

    Question if statement


    I have created a form to edit information that was created earlier in another form. The edit form has a few more fields then the initial form used to enter information. Before the record is updated i wanted to verify that all information has been input in each field so i created the following code.

    Code:
        
    
    if IsNull (Me.[Resolution Time Frame]) then
    MsgBox "Please Click on Resolution Time Frame", vbCritical, "Incomplete details"
          
    ElseIf IsNull(Me.Service_Person) Then
    MsgBox "Please Enter the Technician who worked on the fault", vbCritical, "Incomplete details"
       
    ElseIf IsNull(Me.Cause) Then
    MsgBox "Please enter the cause of fault identified by the technician ", vbCritical, "Incomplete details"
       
    ElseIf IsNull(Me.Solution) Then
    MsgBox "Please enter the the solution used to fix the fault", vbCritical, "Incomplete details"
       
    
    Else
    DoCmd.Save
    End If
     
    End Sub
    how ever i only want the above code to run if field "status" is equal to "Closed" or Resolved"

    if Status is equal to anything else then bypass the above code and save

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    So do a nested If Then Else. What event do you have this code in?

    If Me.status = "Closed" or Me.status = "Resolved" Then
    'do this
    Else
    'run your original code
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57
    Quote Originally Posted by June7 View Post
    So do a nested If Then Else. What event do you have this code in?

    If Me.status = "Closed" or Me.status = "Resolved" Then
    'do this
    Else
    'run your original code
    End If
    I did think of that logic however i am a bit confused of the statement to use after the first then.




    Code:
    Private Sub btn_update_Click()
    
    If Me.status = "Closed" or Me.status = "Resolved" Then 
    
    if IsNull (Me.[Resolution Time Frame]) then
    MsgBox "Please Click on Resolution Time Frame", vbCritical, "Incomplete details"
          
    ElseIf IsNull(Me.Service_Person) Then
    MsgBox "Please Enter the Technician who worked on the fault", vbCritical, "Incomplete details"
       
    ElseIf IsNull(Me.Cause) Then
    MsgBox "Please enter the cause of fault identified by the technician ", vbCritical, "Incomplete details"
       
    ElseIf IsNull(Me.Solution) Then
    MsgBox "Please enter the the solution used to fix the fault", vbCritical, "Incomplete details"
       
    
    Else
    DoCmd.Save
    End If
     
    End Sub
    Or

    Code:
    Private Sub btn_update_Click()
    
    If Me.status = "Closed" or Me.status = "Resolved" Then 
    
    IsNull (Me.[Resolution Time Frame]) then
    MsgBox "Please Click on Resolution Time Frame", vbCritical, "Incomplete details"
          
    ElseIf IsNull(Me.Service_Person) Then
    MsgBox "Please Enter the Technician who worked on the fault", vbCritical, "Incomplete details"
       
    ElseIf IsNull(Me.Cause) Then
    MsgBox "Please enter the cause of fault identified by the technician ", vbCritical, "Incomplete details"
       
    ElseIf IsNull(Me.Solution) Then
    MsgBox "Please enter the the solution used to fix the fault", vbCritical, "Incomplete details"
       
    
    Else
    DoCmd.Save
    End If
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Oops, looks like I had it backwards and possibly you don't need to do anything if that criteria is not met. Code is easier to follow if you use indentation.
    Code:
    Private Sub btn_update_Click()
    
    If Me.status = "Closed" or Me.status = "Resolved" Then 
    
        IsNull (Me.[Resolution Time Frame]) Then
            MsgBox "Please Click on Resolution Time Frame", vbCritical, "Incomplete details"
          
        ElseIf IsNull(Me.Service_Person) Then
            MsgBox "Please Enter the Technician who worked on the fault", vbCritical, "Incomplete details"
       
        ElseIf IsNull(Me.Cause) Then
            MsgBox "Please enter the cause of fault identified by the technician ", vbCritical, "Incomplete details"
       
        ElseIf IsNull(Me.Solution) Then
            MsgBox "Please enter the solution used to fix the fault", vbCritical, "Incomplete details"
    
        Else
            DoCmd.RunCommand acCmdSaveRecord
    
        End If
    
    Else
        'do something here if you want to, maybe a MsgBox
    End If
    
    End Sub
    If what you want to save is the record, then note the change in code to do that.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. VBA If Statement
    By BatmanMR287 in forum Access
    Replies: 4
    Last Post: 05-19-2015, 03:13 AM
  2. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  3. 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
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. iff Statement
    By tkandy in forum Access
    Replies: 0
    Last Post: 03-20-2011, 02:31 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