Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Another setfocus problem

Posted on 2004-08-12
18
Medium Priority
?
438 Views
Last Modified: 2008-03-17
I apologize, but none of the previous setfocus solutions have helped me.   I am trying to setfocus to a text box and I am getting the 2110 error message "can't move focus to the control."   Here is the code:

Private Sub cmdApproved_Click()
    Dim stDocName As String
    stDocName = "Entry Form"
    cmbStatus.SetFocus
    cmbStatus.Text = "Approved"            <-------------
    txtApprovalDate.SetFocus
    txtApprovalDate.Text = Format(Now, "short date")
    DoCmd.Save acForm, stDocName
    cmdApproved.Enabled = False
End Sub

Private Sub cmbStatus_Change()
    If cmbStatus.Text = "Completed" Then
        txtCompletionDate = Format(Now, "Short Date")
        cmdApproved.Enabled = False
    Else
        txtCompletionDate = ""
    End If
    txtLastUpdate.Locked = False
    txtLastUpdate.SetFocus                                    <----------------------
    txtLastUpdate.Text = Forms!Welcome!cmbWelcomeScreenName
    txtLastUpdate.Locked = True
    cmdSave.Enabled = True
    cmdCancel.Enabled = True
End Sub

When the cmdApproved button is clicked, it jumps from where my first arrow is down to cmbStatus_Change() as expected, because it changed the value of that combo box.  But when it gets to my second arrow - txtLastUpdate.SetFocus, I get the error message.    Note that when someone simply changes cmbStatus using the drop-down box, there is no error message.  This app was already written before I got a hold of it.  They asked me to lock the txtLastUpdate field so users can't change it manually, so I am now trying to get around that by unlocking whenever necessary.  Thanks for any advice you can give me.
0
Comment
Question by:ladylucy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11784075
Any chance txtLastUpdate.Enabled = False?
0
 

Author Comment

by:ladylucy
ID: 11784090
Nope.   That was mentioned on many of the solutions I found before.  Good guess.  Thanks.
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11784092
Also what if you comented out the txtLastUpdate.SetFocus, and just ran the code like so?

    txtLastUpdate.Locked = False
    'txtLastUpdate.SetFocus                                    <---------------------- Skipp
    txtLastUpdate.Text = Forms!Welcome!cmbWelcomeScreenName
    txtLastUpdate.Locked = True
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11784104
or:

    txtLastUpdate.Locked = False
    Me.repaint
    txtLastUpdate.SetFocus                                    <---------------------- Skipp
    txtLastUpdate.Text = Forms!Welcome!cmbWelcomeScreenName
    txtLastUpdate.Locked = True
0
 

Author Comment

by:ladylucy
ID: 11784149
As I expected... error... "can't reference a property or method for a control unless the control has the focus"    Thanks for trying.
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11784318
Did you try my other suggestion of inserting the Me.Repaint before your setfucus command?
0
 

Author Comment

by:ladylucy
ID: 11784359
Yes.  It didn't work, with or without the setfocus line.  Same error.  
(I am leaving the office briefly... back later.)  Thanks.
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11784602
What version of Access are you running?

Try updating the field without calling the .text property like this:

Private Sub cmbStatus_Change()
    If cmbStatus.Text = "Completed" Then
        txtCompletionDate = Format(Now, "Short Date")
        cmdApproved.Enabled = False
    Else
        txtCompletionDate = ""
    End If
    txtLastUpdate = Forms!Welcome!cmbWelcomeScreenName
    cmdSave.Enabled = True
    cmdCancel.Enabled = True
End Sub

Notice I removed the .Locked lines and the .SetFocus as when updating it like this you should be able to update it while it is locked and without having to set the focus (I just tried it in Access 2003).
0
 

Author Comment

by:ladylucy
ID: 11785662
Access 2000...  OK, that wasn't the actual solution, but it led me to the reason for the problem.    When I did what you said, I got an error on

   cmbStatus.Text = "Approved"      

It said: "The text you entered isn't an item in the list."
Explanation: Only managers can see the Approved button, and clicking the button is supposed to be the only way of changing this field to "Approved"

When I changed the code back to the way it was, and changed the above line to

cmbStatus.Text = "Awaiting Approval"    (which is an item in the list)

it worked!   That means it won't let me setfocus to the next control until I have finished properly setting the value of the last control to an item in the list ... I guess.  

Now I have to figure out how to get around this...  

I wonder why this worked before I locked that txtLastUpdate text box.   I'll have to go back to the previous version and see what else I changed.  There were other changes.
0
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 750 total points
ID: 11785764
Try just reading the value of cmdStatus like I suggested without setting the focus there. That should allow you to get the value even if you are not an admin and the value = "Approved" because you do not need to validate that field unless you set the focus there and then move the focus.
*******************
Private Sub cmbStatus_Change()
    If cmbStatus = "Completed" Then
        txtCompletionDate = Format(Now, "Short Date")
        cmdApproved.Enabled = False
    Else
        txtCompletionDate = ""
    End If
    txtLastUpdate = Forms!Welcome!cmbWelcomeScreenName
    cmdSave.Enabled = True
    cmdCancel.Enabled = True
End Sub
0
 

Author Comment

by:ladylucy
ID: 11785921
I'm not having a problem with checking cmbStatus = "completed"... But that works for populating cmbStatus = "Approved" and not creating any errors!   Yay!

Private Sub cmdApproved_Click()
Dim stDocName As String
    stDocName = "Entry Form"
    cmbStatus = "Approved"      

But of course, now I have another frustration... it is not populating the value of txtLastUpdate at all... whether or not I have the setfocus there.   Aaaaargh!   I will give you the points for helping me with the initial problem.   Thanks for all your help.   You got rid of a lot of frustration.  
0
 

Author Comment

by:ladylucy
ID: 11786027
FYI - I just put in a STOP to step through the code and found that the code does not jump to cmbStatus_Change() when you don't use the following lines:

cmbStatus.SetFocus
cmbStatus.Text = "Approved"

If you simply use:

cmbStatus = "Approved"

it goes to the next line within the same sub.

I guess I'm still stuck...  but your ideas did help me get out of the rut that I was in.  

0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11786136
Ok. Glad I could help. ThanX for the points.
0
 

Author Comment

by:ladylucy
ID: 11786180
No problem... Thank you.   Watch for my question about populating a combo box with a value that is not in the list!   Haha!   You showed me how to do it quite nicely, but somehow it isn't acknowledged as a "change."   But I should put this under a new topic. It's no longer a setfocus issue.   Tata!
0
 

Author Comment

by:ladylucy
ID: 11893858
OK, I had cmbStatus.LimitToList equal to True.    duh!!!!      So I added to the code... see arrows...

Dim stDocName As String
    stDocName = "Entry Form"
    cmbStatus.LimitToList = False            <------------
    cmbStatus.SetFocus
    cmbStatus.Text = "Approved"          
    cmbStatus.LimitToList = True         <-------------
    txtApprovalDate.SetFocus


Now it works....
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11893965
Excelent. Glad you got it worked out!
0
 

Author Comment

by:ladylucy
ID: 11894043
Yeah, I was on vacation last week...  Came back and looked at it with a clear and rested mind.  And bingo!  ...a VERY SIMPLE answer.   How silly.
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 11894206
Amazing what a break can do.

God bless!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

618 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