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: - txtFileName.Enabled = True
-
txtFileName.Visible = True
-
txtFileName.SetFocus
-
txtFileName.Text = "some value"
The error occurs on the last line.
11 9614
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.
@Veeves - Dim txtB As TextBox
-
-
Set txtB = Me![txtFileName]
-
-
txtB.Enabled = True
-
txtB.Visible = True
-
txtB.SetFocus
-
txtB.Text = "some value"
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.
This code was working until I added a couple of queries and changed some code in a different function. I don`t get it.
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
What happens if you omit the last line of code, simply using - txtFileName.Enabled = True
-
txtFileName.Visible = True
-
txtFileName.SetFocus
Is the cursor blinking in the textbox?
Welcome to Bytes!
Linq ;0)>
BTW, your original code works just fine for me!
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.
try this: -
Dim txtB As TextBox
-
-
Set txtB = Me![txtFileName]
-
-
txtB.Enabled = True
-
txtB.Visible = True
-
txtB.SetFocus
-
txtB.Value= "some value"
-
txtB.Requery
-
the requery should display the value after it's been assigned, if the value still exists.
-AJ
@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)>
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.
Yes the textbox.requery does display the value. Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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....
|
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....
|
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...
|
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,...
|
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
...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |