Solved

How can i close the screen without killing the app?

Posted on 2015-01-29
43
66 Views
Last Modified: 2016-02-11
Hi Experts,
I got the attached error in a ADP, and would like to close the screen without having to kill the application, how can I accomplish it? (cntrl+break doesn't help here..)
untitled.bmp
0
Comment
Question by:bfuchs
  • 20
  • 17
  • 3
  • +2
43 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40578985
close the message box
click on the Reset icon (square button) below the Add Ins and Window Menu (see the image you uploaded)
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40578996
I cant close the message box, it keeps popping up.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40579012
@Ray,
See attached..
untitled.bmp
0
 
LVL 24

Expert Comment

by:chaau
ID: 40579019
Click on the Stop button (On the VBA Toolbar) - a blue square, like on a DVD remote
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40579036
Try doing a CTRL-Break before clicking on the OK button.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40579043
Hi,
I cant get rid of the message box that's having the focus, as soon as I click it comes another one, and that's not allowing me to click anywhere else.
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40579050
You are probably going to have to kill the app.  Depending on what is causing the problem, it could stop.  Is it being generated for each time the procedure is entered?  If so, it will stop when the driving source is exhausted.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40579053
@Pat,
its trying to apply a filter to a continuous form, (and I guess something is wrong with the filter's sql).
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40579079
Did you try doing a CTRL-Break before clicking on the OK button of the message box?  If you don't have too many records in your continuous form, you can try clicking OK until it finishes the number of records.  In other words, clicking OK 30 times if there are 30 records in your continuous form.  Of course this may not be practical depending on the number of records.

Why do you not want to kill it and just take a look at the SQL for the offending syntax?
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40579120
@IrogSinta,
I did try that too, its acting the same as when I click ok
already clicked ok endless times, afraid there are thausands of records..
if I kill the app I lose whatever was done since last saved..
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40579511
<if I kill the app I lose whatever was done since last saved.. >

this is a very common mistake, revising codes and run to test without saving..

kill the app from the Task Manager

build the sql, and check for correct syntax (save ) before applying to wherever you will use the filter.
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40581682
We all make mistakes like this from time to time.  I have the scars to prove it.  I also have a flat spot on my forehead from where the palm of my hand hits it as I say duh!  (that's the g rated version)
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40582753
Hi Experts,
Taking the following comments into account
this is a very common mistake,
We all make mistakes like this
And adding the following:
you can try clicking OK until it finishes the number of records
I thought of the following, how about creating a script that switches focus to the access app and sends the {Enter} key a number of times..

Can someone help me with the code?

Thanks,
Ben
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40582883
Wow, you really don't want to let this go, do you?
:-)

Well here's some code you can try but no guarantees.  Run this from a module and see if it works for you.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)


Private Sub AutoOK()
    Dim hWndParent
    Dim sWindowTitle As String

    sWindowTitle = "Microsoft Access"
    hWndParent = FindWindow(vbNullString, sWindowTitle)

    Do While hWndParent <> 0
        AppActivate (sWindowTitle)
        SendKeys "{Enter}", True
        
        hWndParent = FindWindow(vbNullString, sWindowTitle)
    Loop

End Sub

Open in new window

Ron
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40582915
@IrogSinta,
from where should I run it?
I tried running it from a public module in another access db, and the following is 0 at the first place.
hWndParent = FindWindow(vbNullString, sWindowTitle)
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40582939
Also tried saving it as vbs and got the attached.
untitled.bmp
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40582968
Yes, you did it right when you ran it from another module.  I'm not sure why hWndParent is returning 0. FindWindow was supposed to find the window with the title "Microsoft Access".  It looks like your message box has this title as far as I can tell from the image you included with your first post.   Maybe someone else can chime in.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40583008
@IrogSinta,

Are you sure about the fact that I only have to click OK up to the qty of records in the form?

For testing purpose, I copied that app and changed the record source to contain only a few records, then tried running that troubled filter, and so far the error messages are not ending..

See attached.
Untitled.png
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40583020
I would venture to say that the number of times a message comes up would be, at the least, the same as the number of records.  However, it could be double, triple, quadruple, etc. depending on what the error is.  For instance, if the error comes from a function that is used by two calculated fields in the query, you would get two messages per record.  If the function itself has a loop that errors, you would get as many messages as the number of times it loops for each record.  There are many other possible scenarios for this.  

I just did a test with 5 records and in my case I received 5 error messages.

As an aside, I have found that when I have to redo my work because I failed to save, I usually find it quicker to finish the second time around and what's more, I end up coding it even better.  So don't be afraid of what you'll lose if you close the app.  It may work out for the better.

Ron
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40583170
Hi Ron,

To be honest, I knew from the beginning that this is not a simple matter, and would have to kill the app in this case anyway, however the reason I did post this question and so eager to get a solution is, as this already happened to me a number of times, therefore I would like once and for all to find a solution to this problem.

btw, I tried again running your code from an access module and this time it did not return 0, the screen was just jumping every second, while on the other side I was not able to determine if it had any affect on the other access app, as when I switched focus, only saw the screen full of error messages, the same as it looked before, how can I prove that its actually working as desired?

Thanks,
Ben
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40583185
Ben, all I can suggest is that you just let it run check it after awhile.  Your only other choice right now is to kill the process.  So what have you got to lose by letting it run for a bit.  One way or the other, you should try to make it a habit to save regularly.

Ron
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 40583242
if you don't want to consider the post at http:#a40579511 then I don't think any suggestion could help you resolve your problem.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40585027
@IrogSinta,
Actually I did like the solution you posted above (ID: 40582883), if I can only prove it works..
I tested with another app just having one form open and one text box having the focus, then tried running your code sending some characters thru sendkeys, but so far I don't see them displayed anywhere, also tried inserting a msgbox and see where does it popup, and it did on the db containing the module of your code..

@Ray,
I believe that if we find a solution for this (besides of killing the app), that other people will benefit of that as well..
Not talking about you experts that writing large code is in the tip of your fingers, and that you would never forget to save your work in the first place..
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40585308
You have to realize that the code is looking for a window that has the words "Microsoft Access" in the title bar.  If you don't set up your test correctly, it will not work.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40585408
@IrogSinta,
I think this time the test was correct, can you tell me what's wrong?
see attached.
Also when there is no name matching the title it gets immediately 0, therefore I know it did find the form I'm looking for.
Untitled.png
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40585454
Not sure what you're asking about what's wrong.  If you're saying you don't see any characters show up in the textbox, all I see in your Sendkeys is the {Enter} key.  You need to change the Sendkey line in order to send some characters.   Also, if you're testing this on a form and not a dialog box, you need to set the form's Pop Up property to True.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40585474
Actually I did send that too (pic was cut of), and also tried only sending sendkeys "A",true.
When I change the forms popup property to true, it gets immediately set to 0.
also tried changing border style to dialog, didn't help either.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40585513
I believe if you change it to pop up, the title of the form is different.  So be sure to revise accordingly.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40587383
Hi Ron,

Ok I did correct that,  and it looks like the popup is getting the focus (something is popping up on screen), but I still cant get those characters in the text box, what else can we try?
See attached.

Also tried the following and didn't work.
        Screen.ActiveForm.text0.SetFocus
       ' Forms!TestOKFrm.text0.SetFocus

Thanks,
Ben
Untitled.png
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40587738
Not sure why you're having a problem.  I just created a blank form, added a textbox, set it to Pop Up, used the title of that form in my code, used the word "zap" in my SendKeys statement, and it just worked.  I ended up with a textbox with zapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzapzap.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40587799
Maybe because I use an old version of Access (2003)?
can you upload your db  (if it only have this) and I see if that work on my environment?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40587867
Well if you have a 2003 version of access you won't be able to open the one I made using 2013.   I doubt though that this is the case.  The code I provided is simple and FindWindow even works with Access 97 which I use at work.
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 40587871
I've attached the test db with the form similar to yours.
And here's the code I used.  I added a counter so it only loops 10 times:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)


Private Sub AutoOK()
    Dim hWndParent
    Dim sWindowTitle As String
    Dim i As Integer

    sWindowTitle = "Test Form"
    hWndParent = FindWindow(vbNullString, sWindowTitle)

    Do While hWndParent <> 0 And i < 10
        AppActivate (sWindowTitle)
        SendKeys "Han Shot First ", True
        i = i + 1
        
        hWndParent = FindWindow(vbNullString, sWindowTitle)
    Loop

End Sub

Open in new window

db1.accdb
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40587883
At work I have one pc with 2010, would I be able to open it?
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40587897
I'm not certain.  Why don't you send me the blank form you made.
0
 
LVL 3

Author Closing Comment

by:bfuchs
ID: 40590291
Thanks Ron,
This finally worked.

For some reason, this only works when letting the code run, but not when stepping thru the code line by line, and there was my problem.

BTW, while testing this,  I experienced another strange thing with sendkeys, that I placed a command button on the screen to set focus to that text box and sendkeys "aaaaa", true. only when I click the first time it works, and later doesn't, but if I go manually remove one of those a's then it refills it to 5, in case you have an explanation, please share it with me..

Thanks,
Ben
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40590339
So when the application gets activated, whatever control has the focus at the point receives the SendKeys instruction.  When you manually removed the characters, the focus went to the textbox so it was able to display the characters sent.  When the command button had the focus, it received the characters but did not do anything with them because it needed the {Enter} key to be sent.

So where you able to recover and save your database?
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40590352
Hi Ron,

Not really, I actually had me.text0.setfocus first before I did the sendkeys.

Re recovery of the database, as mentioned earlier, I was about to kill the app anyway as I simply couldn't afford to hold back programming while we figure out this..The reason I needed this to work is for the future, hopefully your solution will work then.

If it doesn't I will post again-:)
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40590480
Using me.text0.setfocus will not work in the module used to activate another application.  The Me keyword refers to the form where the code is and not to another application that you just set focus to.  The reason the code works with a single textbox on a popup form is because that control would automatically have the focus.  If you had other controls on the form, then you'd have to worry about which one you wanted to focus on.

The principle is the same as a message box with an OK button.  The OK button by default has the focus if you select the message box so SendKeys "{Enter}" would have closed it.  I'm surprised you didn't let the code run to see if it killed all your message boxes.  It seemed you would have had nothing to lose if it didn't work.  

Anyways, try getting into the habit of saving often.

Ron
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40592514
Hi Ron,

I was referring to the other strange issue (about the 5 aaa's) when I mentioned the Me keyword.

Attached sample database where you can see what I mean, try to click twice on button, and then also try to remove some a's and click again.

(You don't need to spend too much time on this as its really another issue...,if you see its getting complicated I will post in another question)

I actually killed the app a day after I posted this question, while you posted this solution later on..

The reason I not always save while developing new stuff, is that in case it does not work as desired I don't want to keep it...But of course that poses the risk of losing everything since last saved..

Now with your solution, maybe I can run an app in scheduled task every half hour, that looks for all unsaved documents and sends the focus there, then sendkeys to save it-:)

Thanks,
Ben
db6.mdb
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40592917
Well this is a different topic so you can just post a new question if you really want the solution to it.  

Ron
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40592942
Well I looked at your db and since the answer is simple and it is still related slightly to the flow of this thread, I'll answer it here.  When you set focus to your textbox, your text is automatically highlighted.  So when you send the next set of letters, they just overwrite your original set.  If you want to append the letters you can add Me.Text1.SelStart = Me.Text1.SelLength before your SendKeys statement.

I'm assuming you just wanted to see why this was behaving this way and that you don't really append text in this manner, right :-)
0
 
LVL 3

Author Comment

by:bfuchs
ID: 40592946
Thanks a million Ron!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now