473,804 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code only works when stepping through code line by line

63 New Member
Any idea why code would work as intended when setting a breakpoint and stepping through it line by line, but won't work correctly at run-time?

The code is too much to post, so I hope this summary of the setup will suffice:

There are 3 forms:
  • MainForm
  • recordForm (subform on MainForm)
  • dlgForm (pop-up form)
A button on MainForm opens dlgForm. (dlgForm is declared as an object variable.)

If "OK" is clicked on dlgForm, a custom event is triggered in that form's Close event which switches the recordForm's recordsource to the table. The focus is (supposed to be) shifted to a control in recordForm and the following line is called to create a new record in the table:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdRecordsGoToNew
Everything hinges on the focus being shifted to the subform.

When the code runs, the dlgForm retains the focus despite the "setfocus" commands in the event code and the "new record" command throws an error that the command is not available.

If I set a breakpoint in the dlgForm's Close event and step through the code line by line, the focus shifts as it should and all works well.

Sorry for the long post. Any ideas would be much appreciated!
May 29 '09
15 6266
FishVal
2,653 Recognized Expert Specialist
Ok.

Seems it is a synchronization issue.
I suggest you to run form timer and do all the job in Form_Timer handler.

Expand|Select|Wrap|Line Numbers
  1. Private Sub newDlg_CreateNewItem(itmType As String, newItm As Integer, itmID As Long)
  2.     Me.TimerInterval = 1
  3. End sub
  4.  
  5. Private Sub Form_Timer()
  6.     Me.TimerInterval = 0
  7.     Me.[recordForm_SubformControl].SetFocus
  8.     DoCmd.RunCommand acCmdRecordsGoToNew
  9. End Sub
  10.  
Jun 1 '09 #11
postman
63 New Member
@FishVal
SUCCESS! THANK YOU!

So, it needed a millisecond to complete the closing of the dlgForm before proceding through the next set of procedures?
Jun 1 '09 #12
FishVal
2,653 Recognized Expert Specialist
@postman
You are welcome.

So, it needed a millisecond to complete the closing of the dlgForm before proceding through the next set of procedures?
I don't think so.
Access rarely do things asynchronously, so 1ms form timer means ring after 1ms and after all operations (e.g. in your case any code after RaiseEvent and, maybe, destroying form object) needed to be done have been completed.
Jun 1 '09 #13
ADezii
8,834 Recognized Expert Expert
Really nice work FishVal. I already put in a request to Mary and NeoPa for a substantial wage increase for you! (LOL)!
Jun 1 '09 #14
NeoPa
32,579 Recognized Expert Moderator MVP
We're impressed too ADezii.

This will result in an immediate doubling of your wages Fish :)
Jun 1 '09 #15
FishVal
2,653 Recognized Expert Specialist
Thanks guys.

I really appreciate you giving me credit ...
... however, wage doubling is too much of a good for me.
Simply bring me All Treasures of the World.

Kindest and sincerest regards,
Fish.
Jun 2 '09 #16

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

Similar topics

1
296
by: Sims | last post by:
Hi, I have been using VC++6 for while and moved to .NET 2002 a short while ago, but i have 2 major problems. First, edit and continue almost never works, (the compiler tells me to look at the output but there is nothing there), but sometimes it works, in the same function at the same line. And secondly, every time i try to step into a function, (F11), i go into disassembly, not the actual code making F11 totally useless.
8
1436
by: Deano | last post by:
Here's the code; Private Sub txtTeachName_LostFocus() If IsNull(Me.txtName) Then 'line A Forms!frmMainform!frmSubform.Locked = True GoTo Exit_txtName Else 'line B Forms!frmMainform!frmSubform.Locked = False 'line C
15
4469
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the application runs flawlessly, but once I call the class from inside a c# windows application the program freezes, crashes etc... there must be a way to make this work inside a windows app as it run great as a command line app.
8
1736
by: Doug Bell | last post by:
Hi, I have been debugging a new VB.Net Application and today, I have been getting an error that I have not seen before This error is now appearing on a line with the following code: lnGUID = lnGUID * 1000 + DatePart(DateInterval.DayOfYear, Now) this line runs fine in another App. The Error that I am getting is: "There is no source code available for the current location"
2
1541
by: Ed Leafe | last post by:
Hi, Thanks to the help of many on this list, I've been able to take code that is created by the user in my app and add it to an object as an instance method. The technique used is roughly: nm = "myMethod" code = """def myMethod(self): print "Line 1" print "My Value is %s" % self.Value
3
1408
by: ohnoonho | last post by:
Hello, I posted this in the C# group but thought maybe the better place would be here since it is happening with website projects so please forgive any cross posting. In my website projects I can set a breakpoint, run the app, the breakpoint gets hit, and I can step through or check some variables or what not, and if I hit stop it appears that the rest of the method (and any calling method) continues to execute. I know this because...
3
1407
by: swingingming | last post by:
Hi, I made an access application. And in some cases, it gives me error. And when I tried step by step execution, it worked fine. And every time afterwards. But it gave me the wrong answer before I do the debug. Is it possible that some code gets skipped? Thanks, ming
4
1860
by: Torben Laursen | last post by:
Hi Is there a way to prevent the debugger from stepping into the stl code when I am debugging my code? Thanks Torben
1
1692
by: battlestarguy | last post by:
I have been creating a database that keeps track of the number of tools in our shop. To keep the upkeep of this database simple, I have created buttons that will import all the relevent data from Excel sheets they alreay use. With this button, I move through each record in the excel sheet, coping it to a new table (I call that 'tempImport'), which is then used to update the main tool inventory table. The 'tempImport' table that I use when...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.