Solved Break Point Loop

mloucel

Member
Local time
Today, 02:38
Joined
Aug 5, 2020
Messages
263
Hello Gurus..

I just came across a weird issue, and I don't know if anyone has a logical explanation for this weird behavior.

I have been working with Colin's @isladogs "Centre Form On Screen" which is a great article, until I was just checking how things moved around the module, just as curiosity, then I place a break point at this point since I got an error and I was trying to figure out what was it:

Code:
    DoCmd.MoveSize (lngWinWidth - frm.WindowWidth) \ 2, _
                 (lngWinHeight - frm.WindowHeight) \ 2

seems the error was in the second line, but I eventually found out the error was NOT in Colin's code but I forgot to remove this line from my own code:
Code:
DoCmd.MoveSize 6500, 3500

once I close the program, and tried to run it again, for some weird reason my code stopped as a break point exactly at the code I mention first, thou the logic says that if I close the whole program and run it again ALL those break points will be removed.
Well that was not the case, I tried the old trick in the book:

Under Debug / Clear All Break Points or Ctrl+Shift+F9

Nothing seemed to work, I even restarted the computer, turn off the computer for 5 minutes, disconnected from the power, do a power clean, restart.

and nothing worked, it was stuck in the same place.

as a last resource, I deleted the Module, and import the module, instead of creating a new module, then copy and paste.

That solved the issue.

But the question still remained, WHY DID IT HAPPEN?, why was the break point never deleted, and NO, it didn't show the big dot while seeing the code, it was clean, except while running the routine, stopped there and on the header I can see the Code Break Point message.

Anyone has an explanation?

Maurice.
 
Unfortunately, phantom break points are a well known 'feature' in Access.
When they occur, the easiest solution is to add a blank line at the place the break point occurs then delete it again, save and compile your project.

For anyone who wants to read the article referenced above, see:
 
Unfortunately, phantom break points are a well known 'feature' in Access.
When they occur, the easiest solution is to add a blank line at the place the break point occurs then delete it again, save and compile your project.

For anyone who wants to read the article referenced above, see:
Thanks Colins, That code has saved me a lot of hours trying the " DoCmd.MoveSize Left, Top "
Is simply genious..

By the way I also figure out that The name of the project has to match as well within:

File / Options / Current Data Base / Application Title

if that is not the same value in:
Code:
     'use project name in line below
     '
    hwnd = FindWindow(vbNullString, "ProjectName")

It creates an error.
I know many of the great programmers [Coders] here will figure that out in a second, but for me, a newbie took me a few trial and error.

Thanks so much.
Maurice.
 
Last edited:
By the way I also figure out that The name of the project has to match as well within:
File / Options / Current Data Base / Application Title
if that is not the same value in:
Code:
     'use project name in line below
    '
    hwnd = FindWindow(vbNullString, "ProjectName")

It creates an error.

That's correct.
As I normally make sure the application title and project title are identical, I hadn't noticed that until now.
It probably affects other methods of centering the form
I'll add a comment in the article to that effect.
 
Last edited:
That's correct.
As I normally make sure the application title and project title are identical, I hadn't noticed that until now.
It probably affects other methods of centering the form
I'll add a comment in the article to that effect.
Colin, could there be another way?
Sorry my knowledge is very short as you can imagine, but I've seen code were you can check [for example] if a form is open or not, or maybe something like where regardless of the name of the project just detecting the project name, we can perform the same, something like:
Code:
Application.VBE.ActiveVBProject.Name

Please apologize me before hand, I barely have 1% of your knowledge, it was just a thought.. I am going to try and see what happens..

I just tried and replaced
hwnd = FindWindow(vbNullString, "ProjectName")
for
hwnd = FindWindow(vbNullString, Application.VBE.ActiveVBProject.Name)

And yes it worked, but the CAVEAT, is as you said Both locations must be named the same, the only advantage to the code is that the user has to make sure that both places are named the same as you said:
" application title and project title are identical "

Thank you kindly.
 
Last edited:
There are 4 example forms with code by different authors.

I had checked after reading your earlier post and made a similar change to Form1:

Code:
Dim strProjectName As String
    strProjectName = Application.VBE.ActiveVBProject.Name
 
     'use project name in line below
    hWnd = FindWindow(vbNullString, strProjectName)
    If hWnd <> 0 And GetWindowRect(hWnd, rct) <> 0 Then
        Height = (rct.Bottom - rct.Top) * TwipsPerPixel("Y")
        Width = (rct.Right - rct.Left) * TwipsPerPixel("X")
    End If

The reason both need to be identical with that code is that different parts of the code use hWnd to reference both the VBE project name and the application name. If they are different, error 2505 occurs
1725581789492.png

The code in that example form (1) isn't mine and the issue could probably be overcome by modifying the code.
However, as nobody else had picked this up in the 4 years since I published the article, doing so is not a high priority in my opinion.

However, thanks again for letting me know about this error - I've now added a comment on the article

In any case, the issue does not affect the other example forms (2/3/4) so my recommendation would be to use one of those instead.
My preferences are Form2 or Form3 (which is all my own code). See the article for more info
 
Last edited:

Users who are viewing this thread

Back
Top Bottom