Solved

Another setfocus problem

Posted on 2004-08-12
18
429 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
  • 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 250 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 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

20 Experts available now in Live!

Get 1:1 Help Now