?
Solved

Help with If statements

Posted on 2006-11-08
5
Medium Priority
?
192 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

800 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