Results 1 to 5 of 5
  1. #1
    Grant Shea is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    30

    VBA IF NOT Coding

    So i wrote out this code and it works how i want but I know there HAS to be a better way to do this? I am new to coding so I am hoping to learn something from this. Please do not tell me to restructure my database.



    I want the code to check cboQuestion5 to see if the value is (Showtunes, Other Earworm, Pop, Country, Rock, OR Standards). If it is not one of those values, prompt the user with the Yes No message box and if no is selected exit the sub. It should also check cboHard5 to see if the value is not Vocabulary. If it is notprompt the user with the Yes No message box and if no is selected exit the sub.

    Code:
       If (Me.cboQuestion5) <> "Showtunes" Then GoTo Next1 Else GoTo HardCheck
    Next1:
        If (Me.cboQuestion5) <> "Other Earworm" Then GoTo Next2 Else GoTo HardCheck
    Next2:
            If (Me.cboQuestion5) <> "Pop" Then GoTo Next3 Else GoTo HardCheck
    Next3:
                If (Me.cboQuestion5) <> "Country" Then GoTo Next4 Else GoTo HardCheck
    Next4:
                    If (Me.cboQuestion5) <> "Rock" Then GoTo Next5 Else GoTo HardCheck
    Next5:
        If (Me.cboQuestion5) <> "Standards" Then
        MsgBoxResult = MsgBox("Easy Round Category 5 is NOT an Ear Worm Question. Are you sure?", vbYesNo, "EAR WORM QUESTION")
        If MsgBoxResult = vbNo Then
        Me.cboQuestion5.SetFocus
        Exit Sub
        ElseIf MsgBoxResult = vbYes Then
        End If
      End If
    HardCheck:
      If ((Me.cboHard5) <> "Vocabulary") Then
        MsgBoxResult = MsgBox("Hard Round Category 5 is NOT a Vocabulary Question. Are you sure?", vbYesNo, "VOCABULARY QUESTION")
        If MsgBoxResult = vbNo Then
        Me.cboHard5.SetFocus
        Exit Sub
        ElseIf MsgBoxResult = vbYes Then
        End If
      End If

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    If Me.cboQuestion5 = "Showtunes" or Me.cboQuestion5 = "Other Earworm" or ....... Then
    Else
    MsgboxResult ....
    End If

    check on cboHard5 comes next

    Tip 1 - use negative only when absolutely forced to. The human brain has a much easier time of handling positives (your not equals on every line - phew!)
    Tip 2 - keep your code lined up correctly, that will help you (and others) a lot when trying to figure out what is going on

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Oops, I should have done it in "code", the MsgboxResult should be indented by a tab!

  4. #4
    Grant Shea is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    30
    Thank you I was having difficulty with the or statement so i reverted to goto.

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Also, you don't need these - "ElseIf MsgBoxResult = vbYes Then", they are superfluous and do nothing.

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

Similar Threads

  1. VBA Coding Help please
    By cfobare79 in forum Programming
    Replies: 6
    Last Post: 12-07-2014, 07:54 PM
  2. Coding within ADO
    By crowegreg in forum Programming
    Replies: 4
    Last Post: 08-20-2013, 01:34 PM
  3. Coding for Sum in vba
    By glen in forum Programming
    Replies: 14
    Last Post: 12-20-2012, 05:10 PM
  4. Need help in VBA coding
    By Kcgp in forum Programming
    Replies: 6
    Last Post: 02-01-2012, 11:22 PM
  5. Bar-Coding
    By texasprincess7 in forum Access
    Replies: 1
    Last Post: 02-12-2009, 10:29 AM

Tags for this Thread

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