Compile Error: End if without block if.

E

ELC

I'm sure I'm forgetting something completely idiotic, but I'm (brand) new to
coding and am trying to use if...then statements to auto-fill subsequent
records after a user makes a selection from a combobox. I have created the
below code, but when I try to execute, I get an error message: "Compile
Error: End if without block if". When I check the definition, I get the
following "Identifier under cursor is not recognized."

Private Sub District_AfterUpdate()
Me.Visible = True
Dim District As String
Me.District.AfterUpdate = District
If Me!District = "Daytona Beach" Then Me!JCCAdd = "444 Seabreeze Blvd, Ste
450"
If Me!District = "Fort Lauderdale" Then Me!JCCAdd = "4500 N State Road 7,
Ste 200"
If Me!District = "Fort Myers" Then Me!JCCAdd = "2080 McGregor Blvd, 3rd Floor"
If Me!District = "Gainesville" Then Me!JCCAdd = "1809 Art Museum Dr, Ste 200"
End If
End Sub

I just can't quite see what I'm missing but hopefully a couple new sets of
eyes can help!! Thank you in advance for any assistance!!
 
T

Tom Lake

ELC said:
I'm sure I'm forgetting something completely idiotic, but I'm (brand) new
to
coding and am trying to use if...then statements to auto-fill subsequent
records after a user makes a selection from a combobox. I have created the
below code, but when I try to execute, I get an error message: "Compile
Error: End if without block if". When I check the definition, I get the
following "Identifier under cursor is not recognized."

You don't need the End If since you're using all single-line If statements.

If a > 7 Then
print a
End If

the above needs the End If

but

If a > 7 then print a

doesn't need the End If.

Tom Lake
 
E

ELC

Okay, thanks, tried that, now it just doesn't do anything. When I go into
form view and select the district, the JCCAdd field doesn't update which is
what I was going for. The code as I have it now is:

Option Compare Database
Option Explicit

Private Sub District_AfterUpdate()
Me.Visible = True
Dim District As String
Me.District.AfterUpdate = District
If Me!District = "Daytona Beach" Then Me!JCCAdd = "444 Seabreeze Blvd, Ste
450"
If Me!District = "Fort Lauderdale" Then Me!JCCAdd = "4500 N State Road 7,
Ste 200"
If Me!District = "Fort Myers" Then Me!JCCAdd = "2080 McGregor Blvd, 3rd Floor"
If Me!District = "Gainesville" Then Me!JCCAdd = "1809 Art Museum Dr, Ste 200"
End Sub

If you see anything else that's obviously wrong with it that you could point
out, I'd really appreciate it. Thanks again for your help!
 
D

Douglas J. Steele

What's the "Me.District.AfterUpdate = District" supposed to be doing? I'd
actually expect that to raise an error...

Try:

Private Sub District_AfterUpdate()
Me.Visible = True

Select Case Me!District
Case "Daytona Beach"
Me!JCCAdd = "444 Seabreeze Blvd, Ste 450"
Case "Fort Lauderdale"
Me!JCCAdd = "4500 N State Road 7, Ste 200"
Case "Fort Myers"
Me!JCCAdd = "2080 McGregor Blvd, 3rd Floor"
Case "Gainesville"
Me!JCCAdd = "1809 Art Museum Dr, Ste 200"
Case Else
Me!JCCAdd = "Unknown district: " & Me!District
End Select

End Sub

If that doesn't work, add a DoEvents after End Select.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top