Solved

Help with If statements

Posted on 2006-11-08
5
190 Views
Last Modified: 2010-04-30
I needs some help

This Access VBA.  I need to combine all these statements and make the last condition this: (if all statments are false then)
Else
  Range("P20") = Month(cboSecondary.Value) + 1 ' Standard Pool Month

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''This is my code.

If Len(cboSecondary.Value) > 3 Then
    If (cboSecondary.Value) = "11/29/2006" Then ' Jan Pool Month
        Range("P20") = 1
    Else
       End If
End If
       
If Len(cboSecondary.Value) > 3 Then
    If (cboPrimary.Value) = "30Govt" Then
       If (cboSecondary.Value) = "1/2/2006" Then ' Jan Pool Month
            Range("P20") = 1
       Else
          End If
    End If
    End If
   
If Len(cboSecondary.Value) > 3 Then
    If (cboPrimary.Value) = "30FHLM" Then
       If (cboSecondary.Value) = "1/2/2006" Then ' Feb Pool Month
         Range("P20") = 2
       Else
       
       End If
 End If
 End If
   
If Len(cboSecondary.Value) > 3 Then
    If (cboSecondary.Value) = "10/31/2006" Then ' Dec Pool Month
        Range("P20") = Month(cboSecondary.Value) + 2
     Else
       
       End If
End If

If Len(cboSecondary.Value) > 3 Then
    If (cboSecondary.Value) = "8/31/2006" Then
        Range("P20") = Month(cboSecondary.Value) + 2 'Oct Pool Month
    Else
       
End If
    End If

If Len(cboSecondary.Value) > 3 Then
    If (cboSecondary.Value) = "11/1/2006" Then 'Nov Pool Month
        Range("P20") = Month(cboSecondary.Value)
    Else
       
       End If
End If

If Len(cboSecondary.Value) > 3 Then
    If Month(cboSecondary.Value) = 12 Then
        Range("P20") = 1
End If
    End If

0
Comment
Question by:ca1358
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 17901194
Try this:

If Len(cboSecondary.Value) > 3 Then
  If (cboSecondary.Value) = "11/29/2006" Then ' Jan Pool Month
    Range("P20") = 1
  End If
 
  If (cboPrimary.Value) = "30Govt" Then
    If (cboSecondary.Value) = "1/2/2006" Then ' Jan Pool Month
      Range("P20") = 1
    End If
  End If

  If (cboPrimary.Value) = "30FHLM" Then
     If (cboSecondary.Value) = "1/2/2006" Then ' Feb Pool Month
       Range("P20") = 2
     End If
  End If

    If (cboSecondary.Value) = "10/31/2006" Then ' Dec Pool Month
        Range("P20") = Month(cboSecondary.Value) + 2
    End If

  If (cboSecondary.Value) = "8/31/2006" Then
    Range("P20") = Month(cboSecondary.Value) + 2 'Oct Pool Month
  End If

  If (cboSecondary.Value) = "11/1/2006" Then 'Nov Pool Month
      Range("P20") = Month(cboSecondary.Value)
    End If

  If Month(cboSecondary.Value) = 12 Then
      Range("P20") = 1
    End If

Else      
    Range("P20") = Month(cboSecondary.Value) + 1 ' Standard Pool Month
End If
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17901198
If Len(cboSecondary.value) > 3 Then


    If (cboSecondary.value) = "11/29/2006" Then ' Jan Pool Month
        Range("P20") = 1
    ElseIf (cboPrimary.value) = "30Govt" Then
       If (cboSecondary.value) = "1/2/2006" Then ' Jan Pool Month
            Range("P20") = 1
       End If
    ElseIf (cboPrimary.value) = "30FHLM" Then
       If (cboSecondary.value) = "1/2/2006" Then ' Feb Pool Month
         Range("P20") = 2
       End If
    ElseIf (cboSecondary.value) = "10/31/2006" Then ' Dec Pool Month
            Range("P20") = month(cboSecondary.value) + 2
        End If
    ElseIf (cboSecondary.value) = "8/31/2006" Then
            Range("P20") = month(cboSecondary.value) + 2 'Oct Pool Month
        End If
    ElseIf (cboSecondary.value) = "11/1/2006" Then 'Nov Pool Month
            Range("P20") = month(cboSecondary.value)
        End If
    ElseIf month(cboSecondary.value) = 12 Then
            Range("P20") = 1
        End If
    Else
        If month(cboSecondary.value) = 12 Then
            Range("P20") = 1
        End If
    End If
End If
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 17901555
If Len(cboSecondary.Value) > 3 Then
    If (cboSecondary.Value) = "11/29/2006" Then
        range("P20") = 1
    ElseIf (cboPrimary.Value) = "30Govt" And (cboSecondary.Value = "1/2/2006") Then range("P20") = 1
    ElseIf (cboPrimary.Value) = "30FHLM" And (cboSecondary.Value = "1/2/2006") Then range("P20") = 2
    ElseIf (cboSecondary.Value) = "10/31/2006" Then range("P20") = Month(cboSecondary.Value) + 2
    ElseIf (cboSecondary.Value) = "8/31/2006" Then range("P20") = Month(cboSecondary.Value) + 2        'Oct Pool Month
    ElseIf (cboSecondary.Value) = "11/1/2006" Then range("P20") = Month(cboSecondary.Value)  'Nov Pool Month
    ElseIf Month(cboSecondary.Value) = 12 Then range("P20") = 1
    Else
        range("P20") = Month(cboSecondary.Value) + 1    ' Standard Pool Month
    End If
End If
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 17901614
or maybe something like this?

If Len(cboSecondary.Value) > 3 Then
    Select Case cboSecondary.Value
        Case "11/29/2006": range("P20") = 1
        Case "1/2/2006":
            If cboPrimary.Value = "30Govt" Then
                range("P20") = 1
            ElseIf cboPrimary.Value = "30FHLM" Then
                range("P20") = 2
            End If
        Case "10/31/2006": range("P20") = Month(cboSecondary.Value) + 2
        Case "8/31/2006": range("P20") = Month(cboSecondary.Value) + 2
        Case "11/1/2006": range("P20") = Month(cboSecondary.Value)
        Case Else:
            If Month(cboSecondary.Value) = 12 Then range("P20") = 1 Else range("P20") = Month(cboSecondary.Value) + 1
    End Select
End If

hope this helps..

Dan
0
 

Author Comment

by:ca1358
ID: 17901779
Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question