Form Focus???? (1 Viewer)

Knildon

Learning by Default
Local time
Today, 06:52
Joined
Jan 19, 2012
Messages
89
OK, I give up!
I have a very simple program. 2 tables and 1 form. The form is used to look up and display data from the tables.
I set the form up to be a popup and I minimize the Access database with
[DoCmd.RunCommand acCmdAppMinimize].
I also set the focus to the input textbox since it is the only box that can be typed into.
Everything works great. The cursor shows up and blinks in the input textbox, but
when I try to enter something in the input textbox nothing happens. The form does not have focus so the typing does not show up until I click on the form or the textbox with the mouse and the form regains focus.
I have tried everything I can think of to get the form to have focus when it pops up but to no avail.:banghead:
Anyone have any ideas on how to fix this or is it just a pipedream on my behalf??
Thanks in advance for any and all help.
Don
 
Have you tried explicitly setting the focus to the form and then to the field after you've minimised the App?
 
Let's see the code you have in the Open and Load events.
 
Thanks for the quick responce.
John,
I don't know how to set explicit in a Sub. :confused: I did add Option Explicit at the top of the page but that didn't help. Same results.

vbaInet,
Good to hear from you again. Here's the code:

[Private Sub Form_Open(Cancel As Integer)
DoCmd.RunCommand acCmdAppMinimize
End Sub
Private Sub Form_Load()
Forms!CallFinderFRM1.SetFocus
Me!txtSearchString.SetFocus
End Sub]

I have to run out for a bit so if I don't answer back right away, you'll know why.

Don
 
vbaInet,
Good to hear from you again.
Good to know you're back for some help.

[Private Sub Form_Open(Cancel As Integer)
DoCmd.RunCommand acCmdAppMinimize
End Sub
Private Sub Form_Load()
Forms!CallFinderFRM1.SetFocus
Me!txtSearchString.SetFocus
End Sub]
So looking at the highlighted parts in red, you are setting focus to the form alright, but you're not setting focus to the textbox on that form. Me will always refer to the form from which the code is being run. So even if you set focus to a form, you still have to use the full reference to any of its controls.
 
vbaInet,
I tried as you suggested, using the full reference, but that didn't work either.
Me will always refer to the form from which the code is being run. So even if you set focus to a form, you still have to use the full reference to any of its controls.
Your analogy has me a little confused. Me is the form that has the controls and the code is being run from. They are one in the same.
Getting focus to the textbox does not appear to be a problem since the cursor is in the box and blinking???
I even removed that line of code and the form still does not get the focus.
I remember reading somewhere that focus cannot be set on a form if it contains controls. Now I can't find where I read that.
I think when I close the app, the app holds the focus and I can't get it back until I click somewhere on the form. I don't know how to overcome that problem.:confused:
I failed to put in my original post that I'm using Access 2000 and the form is opening from the "Startup" menu if that matters.
Maybe I'm asking too much or just going in the wrong direction using "Open & Load" in the code.
Thanks for your help. Maybe something will jump into your mind that will help the cause.
Don
 
Right, so explain the logic behind setting focus to a different form and immediately after setting focus to a control on the form you're currently on? What I mentioned there was based on the assumption that if you are on Form A and want to set focus to a control on Form B.
 
Hello to all,
I think we are getting a little off track with this so let's forget all the previous conversation and let me re-explain my problem.
I have one(1) form with one(1) textbox for input. I would like to:
1. Open the form when the program starts.
2. Close or minimize the Access app and keep the form open.
3. Start typing in the textbox.
Here is the problem:
When I start typing nothing happens even though the textbox has a blinking cursor in it.
How do I get the textbox to accept my typing?
I hope that gives everyone a better view of my problem.
Thanks for all the past help and any future help you may have.:)
Don
Maybe you can't teach an old dog new tricks but I keep trying.
 
vbaInet, I never uploaded anything before. Hope it works.
I'm starting this program from a shortcut on my desktop.
 
Last edited:
It seems that when you use the DoCmd.RunCommand acCmdAppMinimize that the form that open subsequently open in the Background. The only thing I have managed to come up with to bring your form to the Foreground is to change the code to the following;
Code:
DoCmd.RunCommand acCmdAppMinimize
MsgBox "Welcome to the DB"
Clicking on the message box OK ensures that when the form opens it is in the foreground. Dirty but effective :rolleyes:
 
Last edited:
It works fine for me. Maybe it's because I've got it open in Access 2007.

Anyway, try each of the following:
Code:
Private Sub Form_Open(Cancel As Integer)
    DoCmd.RunCommand acCmdAppMinimize
End Sub

Private Sub Form_Load()
    Me.SetFocus
    Me.txtSearchString.SetFocus
End Sub

Code:
Private Sub Form_Open(Cancel As Integer)
    DoCmd.RunCommand acCmdAppMinimize
End Sub

Private Sub Form_Load()
    DoCmd.SelectObject acForm, Me.Name
    Me.txtSearchString.SetFocus
End Sub

Code:
Private Sub Form_Open(Cancel As Integer)
    DoCmd.RunCommand acCmdAppMinimize
End Sub

Private Sub Form_Load()
    Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
    DoCmd.SelectObject acForm, Me.Name
    Me.txtSearchString.SetFocus
    Me.TimerInterval = 0
End Sub
 
John and vbaInet,
Thanks for your help and suggestions.

John,
Your idea works fine but as you said, it's a little dirty. The message box opens all by its lonesome on the desktop. Once acknowledged, the input form opens and works as it should. Maybe I can find a way to pretty up the message box.

vbaInet,
I agree that it works when there is another program underneath. When I open my program from Windows Explorer it works as it should but it 's sitting on top of Explorer. I wish it would work that good from my shortcut on the desktop.
I tried all 3 of your methods but had the same results. I thought the timer idea was going to work for sure but it didn't!!!

I noticed something today that I didn't see before. When the form is open I tried the tab key just for the "halibut" and found that Desktop actually had the focus. Don't know how to change that but it's a possible solution to the problem.:rolleyes:

Since I can't do what I want , I'll probly change the focus to the "Search" button and that will force the user to click the cursor on the input textbox. All will be well then.:(

Thanks again for your help. If you have any future ideas on this, please let me know.
Don
71 and still learning to program, I must be a fool!!!!:eek:
 
You could have a look at building a splash screen, to do the job of the MsgBox.
 
and also try increasing the interval from 1000 to 5000. So it will now be 5 seconds. I know it's long but just to test it and see what it does.
 
Re: Form Focus???? Solved

Thanks John,
That's what I was going to try next until I read vbaInet's suggestion.
I increased the timer to 5000 and it worked great. I cranked it back to 2000 and that seems about right. I just had a gut feeling that the timer should work but was dissapointed when it didn't on the first go around.

Put another notch in your guns guys. I received 2 good answers to the problem and now we can consider the problem solved.:(

Thanks again,
Don
 
I'm sure your users can deal with 2 seconds of waiting time ;)

There problem there is that the Access application is no longer the Windows foreground. There's a way of forcing it to become the foreground using an API but you might as well stick with what you have at the moment.

Glad we could help one of our senior citizens. :)
 
and also try increasing the interval from 1000 to 5000. So it will now be 5 seconds. I know it's long but just to test it and see what it does.

I had a play with opening a timed form prior to opening the search form and setting focus to the search field, but it stubbornly remained in the background. The only thing I could find was the MsgBox; the act of clicking it brought the app to the foreground.

I'm pretty sure that it's because DoCmd.RunCommand acCmdAppMinimize sends the app to the background.
 

Users who are viewing this thread

Back
Top Bottom