Solved

Help with If statements

Posted on 2006-11-08
5
187 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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