473,379 Members | 1,544 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,379 software developers and data experts.

Can you stop vba code from running after a DoCmd.Close?

41
I have a rather complicated routine in VBA that performs many checks.

One of the checks will close the window doen using DoCmd.Close, but unfortunately the code tries to continue after this point and causes an error because it is trying to access data on the form I have just closed.

is there a way to tell VBA to DoCmd.Close and then stop running the current subroutine?

I tried End Sub but that causes an error too.
Jan 14 '08 #1
4 4617
JKing
1,206 Expert 1GB
What error are you receiving?

Post a snippet of the offending code if you can.
Jan 14 '08 #2
Craggy
41
What error are you receiving?

Post a snippet of the offending code if you can.

Well the error being received is due to the code continuing and attempting to perform actions based on the form that I have just closed.

Basically after some calculations I want the routine to close the form and stop if a condition is met. if not it will then continue and go to another record.

obviously I dont want the code to continue after the form closes since it is going to try and open a new record on a form that is no longer open.


I know i can work arround this by adding another condition to the logic after the "close" check but this seems a little unecesary if there is a way to prematurely perform an End Sub.



here is the section of the code causing the problem:
Expand|Select|Wrap|Line Numbers
  1. Me.goto = DLookup("[answer links to]", "answer", "[answer id] = list2")
  2. Me.quit = DLookup("[answer ends]", "answer", "[answer id] = list2")
  3.  
  4. 'check to see if this is the last question
  5.  
  6. If Me.goto = 83 Then
  7. MsgBox "Questionnaire complete"
  8. DoCmd.Close
  9. End If
  10. If Me.Questionlinks = 83 Then
  11. MsgBox "Questionnaire complete"
  12. DoCmd.Close
  13. End If
  14.  
  15. 'after checks have been made and data saved open new question
  16.  
  17. If Me.multiple = 0 Then
  18.  
  19. 'if its a select one question then...
Jan 14 '08 #3
JKing
1,206 Expert 1GB
I guess there are two approaches you could take. One would be to use an else block.

Expand|Select|Wrap|Line Numbers
  1. If Me.goto = 83 And Me.QuestionLinks = 83 Then
  2.     Docmd.Close
  3. Else
  4. 'The rest of your code
  5. End If
  6.  
Or you could try the Exit Sub command.
Expand|Select|Wrap|Line Numbers
  1. If Me.goto = 83 Then
  2. Docmd.Close
  3. Exit Sub
  4. End If
  5.  
Jan 14 '08 #4
Craggy
41
Thanks!

Exit Sub is exactly what i was looking for.

I could have worked arround it with Else blocks but i think it would have become unecesarily complex (there are many other sections after this piece of code.)

thanks again.
Jan 15 '08 #5

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

Similar topics

2
by: Julia Baresch | last post by:
Hi everyone, As some of you may know, we've been having trouble with an unrecognized database format error. Today I installed an unfinished project on the workstation of one of my users. ...
0
by: Koontzie | last post by:
Hello all, I have a form in Access XP that returns all printers intalled on the users system. The select which printer they want to print to and click a "Next" button. The button click event...
0
by: Koontzie | last post by:
Hello all, I have a form in Access XP that returns all printers installed on the user's system. They select which printer they want to print to and click a "Next" button. The button click...
5
by: MLH | last post by:
Having identified a A97 bug in which acDialog causes undesirable side effects processing the opened form, I would like to replace the following code running in MyForm ... DoCmd.OpenForm...
6
by: Bob Alston | last post by:
I am looking for Access reporting add-in that would be easy to use by end users. My key focus is on selection criteria. I am very happy with the Access report writer capabilities. As far as...
5
by: Arno R | last post by:
Hi all, I am using the DetectIdleTime code from MS to shut down an app when not in use for a certain time. http://support.microsoft.com/?kbid=210297 I use a hidden form FrmDetectIdeTime with a...
3
by: jpr | last post by:
Hello, I have a form on which I have a cmdbutton to copy a couple of fields into another table (MASTER) using the SSN on the active form as criteria. In the active form (based on a tables...
1
by: jhicke03 | last post by:
Hi, This problem has been bugging me for a while. In my form's before update field i have the following code: Private Sub Form_BeforeUpdate(Cancel As Integer) If Me.Nominator_name = "" Or...
6
by: Phil Stanton | last post by:
I am running a query that calls a function used to format addresses depending on the width of a control on a report that shows that address. The same query is used as the RecordSource of lots of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.