473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

SetFocus does not work in Access form

5
I have an unbound field on a form. In the onClick event I have code to populate a text field. I first setFocus to it and enable it. Both of these actions work. But when my code reaches the the line whete I set the textfieldname.text to a value, I get an error: You can`t reference a property or method unless the control has focus.

My code is:
Expand|Select|Wrap|Line Numbers
  1. txtFileName.Enabled = True
  2. txtFileName.Visible = True
  3. txtFileName.SetFocus
  4. txtFileName.Text = "some value"
The error occurs on the last line.
Sep 16 '09 #1
11 9614
Studlyami
464 Expert 256MB
Are you able to use the Value property instead? Also have you tried the syntax Me!txtFileName.SetFocus. I haven't done much with access so those might not work, but we do have a specific forum section for these types of questions so a moderator will probably move this topic over there.
Sep 17 '09 #2
ADezii
8,834 Expert 8TB
@Veeves
Expand|Select|Wrap|Line Numbers
  1. Dim txtB As TextBox
  2.  
  3. Set txtB = Me![txtFileName]
  4.  
  5. txtB.Enabled = True
  6. txtB.Visible = True
  7. txtB.SetFocus
  8. txtB.Text = "some value"
Sep 18 '09 #3
NeoPa
32,556 Expert Mod 16PB
I checked the help file & I can't see why that wouldn't work.

Does this happen in all circumstances? perhaps there's something else going on we don't know about.
Sep 18 '09 #4
Veeves
5
This code was working until I added a couple of queries and changed some code in a different function. I don`t get it.
Sep 18 '09 #5
ajalwaysus
266 Expert 100+
Does any of those changes have an effect on your current form? If so, setting focus should be the last thing you do, to allow for all the changes to happen.

-AJ
Sep 18 '09 #6
missinglinq
3,532 Expert 2GB
What happens if you omit the last line of code, simply using
Expand|Select|Wrap|Line Numbers
  1. txtFileName.Enabled = True
  2. txtFileName.Visible = True
  3. txtFileName.SetFocus
Is the cursor blinking in the textbox?

Welcome to Bytes!

Linq ;0)>

BTW, your original code works just fine for me!
Sep 18 '09 #7
Veeves
5
If I omit the last line: txtFileName.Text = "some value", then I avoid the error but don`t get the textbox filled with a value.

I changed txtFileName.Text to txtFileName.Value, and this works but the textbox shows as empty instead of the text I want.

I did some investigating and found that the problem starts when I delete all the records from the table which is the record source for the form using:
CurrentDb().Execute "DELETE FROM Primary_Data"

After running this the problems with SetFocus started.
Sep 18 '09 #8
ajalwaysus
266 Expert 100+
try this:
Expand|Select|Wrap|Line Numbers
  1. Dim txtB As TextBox
  2.  
  3. Set txtB = Me![txtFileName]
  4.  
  5. txtB.Enabled = True
  6. txtB.Visible = True
  7. txtB.SetFocus
  8. txtB.Value= "some value"
  9. txtB.Requery
  10.  
the requery should display the value after it's been assigned, if the value still exists.

-AJ
Sep 18 '09 #9
missinglinq
3,532 Expert 2GB
@Veeves
You didn't answer my question, though! If you omit the last line, then run the code (click the button,) does the textbox, in fact, receive the focus, i.e. does the cursor appear in the textbox?

Linq ;0)>
Sep 18 '09 #10
Veeves
5
If I omit the last line: txtFileName.Text = "some value", then the textbox does receive focus.

One time I stopped execution right after the textBox.SetFocus. All the properties had a value of :Cannot access the property of a control that does not have focus (not exactly this message but very close), with one exception, the value property had a value and I was able to display it.
Sep 18 '09 #11
Veeves
5
Yes the textbox.requery does display the value. Thanks.
Sep 18 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Corepaul | last post by:
I am a newbie using Access 2000. I am using the following test in the txtAlbum OnExit procedure to prevent leaving an empty text box for a required field If (IsNull(txtAlbum.Value)) Or...
10
by: dale zhang | last post by:
Hi, I saw the post here about setfocus. But they are for web form. Web control page HTML does not have form1. the Jscript there does not work here. My question is how to set focus to the...
4
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1....
2
by: Gil | last post by:
can you set focus to the current access application through vba? lets say i tell access to open another application and that new application gains the focus and causes access to loose the focus....
0
by: z.ghulam | last post by:
Hi, I'm creating a new databse and have a couple of problems I'd greatly appreciate any feedback on. 1) I have an order form and would like to set it, so that when the form is opened, the focus...
1
by: fonzie | last post by:
I a form with tab control will all fields based on one table. I have some code setup for the 'On Change' event of the tab control that checks to see if a field on the main form is null. If it is,...
5
agroover
by: agroover | last post by:
I can't seem to figure out how to get rid of the errors. I recieve the following error when I leave the Grade.SetFocus in my code... Microsoft Access can't move the focus to the control Grade ...
3
by: ckrows | last post by:
I have a main form with a button that makes a subform visible. I added a button in the form footer of the subform that is supposed to hide the subform. This does not work because the focus is on...
6
by: Whizzo | last post by:
Hi folks; I spent a little while some time ago building a touchscreen data entry interface into an Access 2003 form. I'm not too experienced in VBA at all so I was quite happy when I came up with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.