473,795 Members | 2,630 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 #1
15 6264
Megalog
378 Recognized Expert Contributor
Since dlgform is a popup, maybe the focus is being forced to stay on that form until it's closed. On the button's click event, try putting the form's close event first, and then follow it with all the supporting code for MainForm.
May 29 '09 #2
NeoPa
32,579 Recognized Expert Moderator MVP
It's hard to work on one of these remotely, but this sort of thing is down to timing issues, or specifics of rule-bending in order to provide debugging.

Something like the dlgForm being available while debugging because the debugger couldn't work otherwise, yet when running full speed this is closed by that point. I'm guessing to a certain extent as I have not enough contact to see the whole picture clearly.

One way to fix this is to avoid any possibility of conflict. Perhaps the dlgForm code could invoke a procedure within one of the other forms' modules instead. Whichever seems the easiest or more appropriate to you.

Let us know how you get on.
May 29 '09 #3
NeoPa
32,579 Recognized Expert Moderator MVP
I've just seen Megalog's response, and it occurs to me that it may be this simpler explanation (I always seem to find a complex answer when easier ones are more obvious).
May 29 '09 #4
ADezii
8,834 Recognized Expert Expert
@postman
As far as the Focus issue goes, transfer the Focus as a 2-Step process fully qualifying the Paths as in:
Expand|Select|Wrap|Line Numbers
  1. Forms!MainForm![recordForm].SetFocus
  2. Forms!MainForm![recordForm].Form![<Control on recordForm>].SetFocus
Let us know if this works out.
May 30 '09 #5
postman
63 New Member
@ADezii
I tried this and get the same issue--the dlgForm continues to retain the focus.

Here are a few more details I extracted that I hope may clarify the issue. As mentioned, the dialog form is declared as a variable in the MainForm module:
Expand|Select|Wrap|Line Numbers
  1. Private WithEvents newDlg As Form_dlgForm
The button on MainForm that opens the dialog uses this code to do so:
Expand|Select|Wrap|Line Numbers
  1. Set newDlg = New Form_dlgForm
  2. newDlg.Visible = True
On the dlgForm, the "Form_Close " event contains code that raises a custom event:
Expand|Select|Wrap|Line Numbers
  1. Public Event CreateNewItem(itmType As String, newItm As Integer, itmID As Long)
  2. Private Sub Form_Close()
  3.     RaiseEvent CreateNewItem(itmType, Me.Frame4, Nz(newItemList, -1))
  4. End Sub
In the MainForm module, the custom event has the code to peform the previously mentioned actions on the recordForm subform:
Expand|Select|Wrap|Line Numbers
  1. Private Sub newDlg_CreateNewItem(itmType As String, newItm As Integer, itmID As Long)
  2. Form_MainForm.[recordForm_SubformControl].SetFocus 
  3. Form_recordForm.[controlOnSubform].SetFocus 
  4. Form_recordForm.RecordSource = "myTable"
  5. DoCmd.RunCommand acCmdRecordsGoToNew
  6. End sub
Jun 1 '09 #6
FishVal
2,653 Recognized Expert Specialist
What about Megalog's hypothesis - could dlgForm.Modal property be True?
Jun 1 '09 #7
postman
63 New Member
@FishVal
No, I double-checked and the Modal property is not set to True.

In regards to Megalog's hypothesis, I agree--but isn't that how it's already setup? The custom event is raised in dlgForm's Close event.
Jun 1 '09 #8
FishVal
2,653 Recognized Expert Specialist
What happens if you get references this way?

Expand|Select|Wrap|Line Numbers
  1. Private Sub newDlg_CreateNewItem(itmType As String, newItm As Integer, itmID As Long)
  2. With Me.[recordForm_SubformControl]
  3.     .SetFocus 
  4.     With .Form
  5.         ![controlOnSubform].SetFocus 
  6.         .RecordSource = "myTable"
  7.     End With
  8. End With
  9. DoCmd.RunCommand acCmdRecordsGoToNew
  10. End sub
What happens if RecordSource is not changed or changed before setting focus on subform's control?
Jun 1 '09 #9
postman
63 New Member
@FishVal
I tried that and the RecordSource suggestion and it's the same thing--will only work correctly when stepping through line-by-line.
Jun 1 '09 #10

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
1735
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
1540
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
1404
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
1859
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
10438
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...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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
10001
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...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.