Results 1 to 6 of 6
  1. #1
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93

    Can't figure out how to end a procedure on meet condition fail


    I have a form with a checkbox and a comand button. When I have the following:

    Code:
    Private Sub cmdContinue_Click()
     
    If Me.chkCertify = False Then MsgBox "You must check the cetification box indicating you have read the warning and certifty the accuracy of the entered information."
     
    DoCmd.OpenForm "frmTrainingMultInput"
     
    DoCmd.Close acForm, "frmSchoolNomMultiple"
     
    DoCmd.Close acForm, "frmTrainingMultInputCertify"
     
    End Sub
    This is the first VBA code I have ever written entirely on my own. If the user clicks the button without the check box selected, the message displays, but when they click 'Ok', it continues the code and opens/closes the forms without the check box ever being selected.

    I am not sure what to put where to get the code to stop and go back to frmTrainingMultInputCertify.

    Thank you in advance for your time and help. Have a great day!

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Code:
    Private Sub cmdContinue_Click()
     
    If Me.chkCertify = False Then 
        MsgBox "You must check the cetification box indicating you have read the warning and certifty the accuracy of the entered information."
     else 
        DoCmd.OpenForm "frmTrainingMultInput"
     
        DoCmd.Close acForm, "frmSchoolNomMultiple"
     
        DoCmd.Close acForm, "frmTrainingMultInputCertify"
    end if
    End Sub

  3. #3
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Thank you...worked like a charm!

  4. #4
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    A related issue. I have the following. What am I doing wrong:

    Code:
    Private Sub cmdContinue_Click()
        If Me.cboCourseName Is Null Then
            MsgBox "'Course' is a required field."
        ElseIf Me.cboCourseStatus Is Null Then
            MsgBox "'Course Status' is a required field."
        ElseIf Me.FROM_DT Is Null Then
            MsgBox "'From date' is a required field.  From and To dates can be the same for one day evolutions."
        ElseIf Me.TO_DT Is Null Then
            MsgBox "'To date' is a required field"
        ElseIf Me.cboFundingStatus Is Null Then
            MsgBox "'Funding Status' is a required field"
        
        Else
        
        DoCmd.OpenForm "frmTrainingMultInputCertify"
        
        End If
        
    End Sub
    Thanks again for your help.

  5. #5
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    I believe you need 4 more End IF, one for each IF. I havent run the code but I believe they can all go after the current End IF. There may be other problems, but thats the first I see.

  6. #6
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Figured it out. Here is what worked:

    Code:
    Private Sub cmdContinue_Click()
    If IsNull(Me.cboCourseName) Then
        MsgBox "'Course Name' is a required field."
        cboCourseName.SetFocus
        Exit Sub
    End If
    If IsNull(Me.cboCourseStatus) Then
        MsgBox "'Course Status' is a required field."
        cboCourseStatus.SetFocus
        Exit Sub
    End If
    If IsNull(Me.FROM_DT) Then
        MsgBox "'From date' is a required field.  From and To dates can be the same for one day evolutions."
        FROM_DT.SetFocus
        Exit Sub
    End If
    If IsNull(Me.TO_DT) Then
        MsgBox "'To date' is a required field."
        TO_DT.SetFocus
        Exit Sub
    End If
    If IsNull(Me.cboFundingStatus) Then
        MsgBox "'Funding Status' is a required field."
        cboFundingStatus.SetFocus
        Exit Sub
    End If
    DoCmd.OpenForm "frmTrainingMultInputCertify"
    End Sub

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

Similar Threads

  1. Cannot Figure this query out
    By ryan1313 in forum Queries
    Replies: 6
    Last Post: 08-13-2010, 12:54 PM
  2. Replies: 2
    Last Post: 07-15-2010, 10:26 AM
  3. Replies: 2
    Last Post: 03-31-2009, 11:15 AM
  4. Easy question...so why can't I figure it out?
    By bdrago527 in forum Access
    Replies: 1
    Last Post: 10-02-2008, 02:40 PM
  5. Can't Figure It Out!!
    By jdohio5 in forum Database Design
    Replies: 1
    Last Post: 05-04-2006, 06:49 AM

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