473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Else with out End If Error not clear.

I am trying to run the following code on a form that requires dates for execution. If the dates are absent I wanted the code to display a MsgBox indicating dates required, then abort. Keep getting the error "Else without If". Any ideas?

Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.BDate.Value) Then GoTo ABORT
  2.  Else
  3.  GoTo Run
  4.  End If
  5.  
  6. Sub Run()
  7. DoCmd.SetWarnings False
  8. DoCmd.RunMacro "Jaimee Report Exports"
  9. DoCmd.SetWarnings True
  10.  
  11. Sub ABORT()
  12. MsgBox "Need to Apply Dates"
  13. End Sub
May 12 '16 #1
5 1046
Luk3r
300 256MB
You have to put "GoTo ABORT" on a new line. If you don't, your If statement thinks it is closed.

Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me.BDate.Value) Then
  2.   GoTo ABORT
  3. Else
  4.   GoTo Run
  5. End If
  6.  
  7. Sub Run()
  8.   DoCmd.SetWarnings False
  9.   DoCmd.RunMacro "Jaimee Report Exports"
  10.   DoCmd.SetWarnings True
  11. End Sub
  12.  
  13. Sub ABORT()
  14.   MsgBox "Need to Apply Dates"
  15. End Sub 
May 12 '16 #2
zmbd
5,501 Expert Mod 4TB
Please see the trouble shooting section:
https://bytes.com/topic/access/answe...on#post3803251

If you follow the advice provided there you will locate and eliminate a good deal of these types of errors
:)
May 13 '16 #3
Luk3r
Thanks for the response. In Access VBA I cannot run the code as you indicate. I get a compile error that ID's the RUN subroutine. When I place the End Sub as indicated it generates a break in the code so the Labels are not recognized. Also if I run this way it says it expects an END SUB after the End if.

Any thoughts?

Thanks
May 13 '16 #4
jforbes
1,107 Expert 1GB
Follow both Luk3r and zmbd's advice and then in your code, change GoTo to Call.
May 13 '16 #5
zmbd
5,501 Expert Mod 4TB
TopCerv
Why don't you post your actual code?

I was suspecting that you posted snippets of your code in the original post as the way it is there it will give you an invalid outside of procedure in the If-Then, amongst other issues!

Luk3r gave you a very nice re-work of the code you posted. However, the opening IF-Then still will NOT work outside of a procedure. I can only surmise that Luk3r was also of the impression that you were providing only a small section of your actual code.

Jforbes is right on the mark with the Call -- Keep in mind that this is VBA and not BASIC - same language different dialect :)
GOTO are now generally used only with the ON ERROR. GOTO and GOSUB have really fallen out of favor, especially in VBA and .NET etc...in fact GoSub was depreciated quite a long time ago.

I've pointed you to the general troubleshooting lead-in. There are more sections in our Insights articles, see the link at the bottom of this page.

Until and unless you can do the basic troubleshooting and post your actual code there really isn't much more we can honestly do for you.... except poke in the dark.
May 13 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Hannibal111111 | last post by:
Hi, I am trying to print out a statement if a record is not found, but I keep getting Error 156: incorrect syntax near Else. Here is the stored procedure: CREATE PROCEDURE...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
0
by: kammaldeep | last post by:
hi, i m newbie 2 PHP & to b frank ... will alwaz be ... i dont think i will go into much details with PHP as my work doesnot include workin with PHP bt i have a forum .. and i want to make a...
9
by: RP | last post by:
I have following code lines: =============================== if (txtMethod.Text != "D") || (txtMethod.Text != "F")) { txtMethod.Clear(); txtMethod.Focus(); } else {
8
by: callumagus | last post by:
Python Version 2.0 Windows Vista (I know, I know...) Im very new to python and have only been doing it for two weeks. print 'Type in lowercase!'; String_Var = raw_input ('Add, Divide,...
3
by: ragtopcaddy via AccessMonster.com | last post by:
I have an error handler: On Error GoTo Outtahere At the end of the routine, the OuttaHere section reads: OuttaHere: If Err.Number <0 Then If Err.Number = 3061 Then Debug.Print " Failed to...
1
by: Karen Rosen | last post by:
This is the first time I am attempting this - someone was kind enough to help me with my previous error and told me to add print statements before the error which I did the error is now invalid...
2
by: tutu saint | last post by:
I have a registration script that sends email through Gmail SMTP with the below script. i received errors (SMTP Error: Could not connect to SMTP host. ) Please what is wrong with this code. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.