Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Message Block if without End If 2

Status
Not open for further replies.

Lavenderchan

Technical User
Jul 21, 2008
132
US
Hi I was writing a code to depending on a task I add a few items to it and it worked fine now all I'm getting is the Error Message Block If without End If. some suggestions I've seen on the web said to count the if statements but I'm not sure if there is to be an equal number of end if's. Any help would be apprecatied.

Here is the code I have so far:
Private Sub cboTask_BeforeUpdate(Cancel As Integer)

If Me.cboTask = ("Annual Operating Budget & Rent Increase Request") Then
Me.Due_Date = Date + 30
If Me.cboTask = ("Annual Operating Budget & Rent Increase Request") Then
Me.Status = ("Active")
End If

If Me.cboTask = ("Annual Financial Statement Response") Then
Me.Due_Date = Date + 30
If Me.cboTask = ("Annual Financial Statement Response") Then
Me.Status = ("Active")
End If

If Me.cboTask = ("2530 New Role for Property") Then
Me.Due_Date = Date + 30
If Me.cboTask = ("2530 New Role for Property") Then
Me.Status = ("Active")
End If

If Me.cboTask = ("2530 Submission") Then
Me.Due_Date = Date + 30
If Me.cboTask = ("2530 Submission") Then
Me.Status = ("Active")
End If

If Me.cboTask = ("Addendum B MOR Form 9834") Then
Me.Due_Date = Date
If Me.cboTask = ("Addendum B MOR Form 9834") Then
Me.Status = ("No Response Required")
End If

If Me.cboTask = ("Affirmative Fair housing Marketing Plan") Then
Me.Due_Date = Date
If Me.cboTask = ("Affirmative Fair housing Marketing Plan") Then
Me.Status = ("No Response Required")
Me.Comments = ("Mail to Cincinnati")
End If
End If

Thanks,
Keri
 
try
Code:
If Me.cboTask = ("Annual Operating Budget & Rent Increase Request") Then
    Me.Due_Date = Date + 30
End If
  If Me.cboTask = ("Annual Operating Budget & Rent Increase Request") Then
    Me.Status = ("Active")
End If
 
If Me.cboTask = ("Annual Financial Statement Response") Then
    Me.Due_Date = Date + 30
End If
    If Me.cboTask = ("Annual Financial Statement Response") Then
    Me.Status = ("Active")
End If
 
If Me.cboTask = ("2530 New Role for Property") Then
    Me.Due_Date = Date + 30
End If
    If Me.cboTask = ("2530 New Role for Property") Then
    Me.Status = ("Active")
End If
    
If Me.cboTask = ("2530 Submission") Then
    Me.Due_Date = Date + 30
End If
If Me.cboTask = ("2530 Submission") Then
    Me.Status = ("Active")
End If
    
If Me.cboTask = ("Addendum B MOR Form 9834") Then
    Me.Due_Date = Date
End If
    If Me.cboTask = ("Addendum B MOR Form 9834") Then
    Me.Status = ("No Response Required")
    End If
    
If Me.cboTask = ("Affirmative Fair housing Marketing Plan") Then
    Me.Due_Date = Date
End If
If Me.cboTask = ("Affirmative Fair housing Marketing Plan") Then
    Me.Status = ("No Response Required")
    Me.Comments = ("Mail to Cincinnati")
    End If
 
Wouldn't this work ok and be a bit simpler
Code:
SELECT CASE Me.cboTask 
    Case "Annual Operating Budget & Rent Increase Request"
        Me.Due_Date = Date + 30
        Me.Status = "Active"
    Case "Annual Financial Statement Response"
        Me.Due_Date = Date + 30
        Me.Status = "Active"
    Case "2530 New Role for Property"
        Me.Due_Date = Date + 30
        Me.Status = "Active"
    Case "2530 Submission"
        Me.Due_Date = Date + 30
        Me.Status = "Active"
    Case "Addendum B MOR Form 9834"
        Me.Due_Date = Date
        Me.Status = "No Response Required"
    Case "Affirmative Fair housing Marketing Plan"
        Me.Due_Date = Date
        Me.Status = "No Response Required"
        Me.Comments = "Mail to Cincinnati"
END SELECT

Duane
Hook'D on Access
MS Access MVP
 
Even Simpler
Code:
Select Case Me.cboTask
    Case "Annual Operating Budget & Rent Increase Request", _
          "Annual Financial Statement Response", _
          "2530 New Role for Property", _
          "2530 Submission"
             Me.Due_Date = Date + 30
             Me.Status = "Active"
    Case "Addendum B MOR Form 9834", "Affirmative Fair housing Marketing Plan"
        Me.Due_Date = Date
        Me.Status = "No Response Required"
        If Me.cboTask = "Affirmative Fair housing Marketing Plan" Then Me.Comments = "Mail to Cincinnati"
End Select
 
Oh I didn't know there were others ways to write it. I've just starting learning about vba.
thank you.
Keri
 
Actually I would probably attempt to model this all in tables rather than hard-coding values into modules. This type of code should either be in tables or functions in a standard module of business calculations.

There are a couple very good resources on the web. Here is one Data belongs in your tables -- not in your code

Duane
Hook'D on Access
MS Access MVP
 
Hi I have taken the advice and put my data in a table so I can use the case method and have it stored in the table instead of the code? I still a little confused?
Thanks,

Keri
 
Yes I did set the table up that way but I'm not sure how to do the code.
 
It would have made sense to reply back with your table and field names. However, try something like:
Code:
Dim strComments As String
Me.Due_Date = Date + DLookup("DatePlus","Yourtable","Task=""" & Me.cboTask & """")
Me.Status = DLookup("Status","Yourtable","Task=""" & Me.cboTask & """")
strComments = DLookup("Comments","Yourtable","Task=""" & Me.cboTask & """") & ""
If Len(strComments) > 0 Then 
   Me.Comments = strComments
End If

Duane
Hook'D on Access
MS Access MVP
 
Hi If my due date is returning a null value do I use the len function or nz?
thanks,
Keri
 
I would make sure the table has values so you wouldn't return nulls. You could use:
Code:
Date + Val(Nz(DLookup("DatePlus","Yourtable","Task=""" & Me.cboTask & """"),0))

Duane
Hook'D on Access
MS Access MVP
 
Hi duane,

Would I get a return null if the value types of my field are different. My table fields are Task,DatePlus,Status and Comments. I have the Date Plus set as a number and my due date field on my form is set as date. I have change both the text and back but I'm still returning a null. for Me.Due_Date? Is it because I did the event before update. It worked fine when I did the values in the code with the select case. I'm confused why I keep getting the 2001 runtime error.
Thanks for your help.
Keri
 
I would use the After Update event of the combo box. Doesn't cboTask have a Row Source of a small lookup table? Is this lookup table the one you used for "My table fields are Task,DatePlus,Status and Comments"?


Duane
Hook'D on Access
MS Access MVP
 
Yes, I figured it out. I was missing my dateplus field in the row source. Thank you very much for your help.
keri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top