473,327 Members | 2,112 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,327 software developers and data experts.

Code only works when stepping through code line by line

63
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 6210
Megalog
378 Expert 256MB
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,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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 Expert 8TB
@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
@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 Expert 2GB
What about Megalog's hypothesis - could dlgForm.Modal property be True?
Jun 1 '09 #7
postman
63
@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 Expert 2GB
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
@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
FishVal
2,653 Expert 2GB
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
@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 Expert 2GB
@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 Expert 8TB
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,556 Expert Mod 16PB
We're impressed too ADezii.

This will result in an immediate doubling of your wages Fish :)
Jun 1 '09 #15
FishVal
2,653 Expert 2GB
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
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...
8
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...
15
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...
8
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 =...
2
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...
3
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...
3
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...
4
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
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.