473,396 Members | 1,760 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,396 software developers and data experts.

Runtime Error '2185' on control that has focus

675 512MB
I've spent all day on this, and can't see what I'm doing wrong. I've Googled and all I find have the same mistake, using .Text when they should use .Value. In this case, .Text is correct.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearch_Change()
  2. Dim wk As String
  3. wk = Me.txtSearch.Text 'This is the statement that gets Runtime Error '2185'
  4. . . .
  5. End Sub
  6.  
I tried wk = txtSearch.Text to no avail.
I tried txtSearch.SetFocus before the use/assignment, also didn't work.
Obviously, the control has the focus, as I am typing in it, and want to monitor what is entered, as it is entered.

Trying to trick Access into doing my bidding, I tried
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearch_Change()
  2. Dim wk As String
  3. cmdExit.SetFocus
  4. wk = txtSearch
  5. txtSearch.SetFocus
  6. txtSearch.SelStart = 255
  7. . . .
  8. End Sub
  9.  
Now wk has the correct information, but the error occurs on the .SelStart = 255 statement. Leaving that out means that the entire string in the TextBox is selected. Not acceptable.

I copied the code for this control to a new database, new form with one control only. The code works. I copied the form to the new database, removed the RecordSource so I wouldn't have to duplicate the entire program. Works fine.

I don't want the code debugged, as the code works. I'm looking for ideas about what, on a form, might conflict with the "Got Focus". You know, like if the TextBox Backcolor is light blue, the moon is full, and the form is modal, there is trouble, so change on of these. That kind of idea.

OldBirdman
Jan 22 '08 #1
6 13565
missinglinq
3,532 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1.  Private Sub txtSearch_Change()
  2.  Dim wk As String
  3.  wk = Me.txtSearch.Text 'This is the statement that gets Runtime Error '2185'
  4.  . . .
  5.  End Sub
  6.  
The .Text property is, indeed, appropriate in this context; it's one of the few times/events where it should be used. And it works fine for me, first time out, as it should have for you! Aside from corruption, which does happen to objects other than forms, I have no idea of what could have caused this! There's obviously code missing, from Line 4 of your post, and I'd be interested in knowing what this code is, for two reasons.

  1. Access is notorious for popping error messages that aren't really germaine to the problem at hand
  2. Access frequently hilites not the line causing the error, but rather the line before the line that is causing the problem
Linq ;0)>
Jan 22 '08 #2
OldBirdman
675 512MB
How can you imply that Microsoft programs might have errors in them? I'm stunned!

The next (and only) line of code missing is:
Expand|Select|Wrap|Line Numbers
  1. Call SetExtension(wk)
  2.  
The code didn't work if the next line of code were "Debug.Print wk" or no more code, only the "End Sub" statement

I added another TextBox to the form, and error '2185' still occurs with
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text42_Change()
  2. Debug.Print Text42.Text
  3. End Sub
  4.  
I then created a new form, from scratch, with only a TextBox, and of course, this code worked, as I stated in my original post. Starting again, with a new form, I copied all the controls and code to the new form, and error '2185' occurred. So I started again, and copied all controls except the TextBox, which I built from scratch using the toolbox.

Now my form works. I don't know why, but it does. Now that I know that Microsoft Access has bugs, I can blame everything on them. But honestly, I have no Idea what is different here from the old form. I certainly copied EVERYTHING EXCEPT the one TextBox Control, which was recreated, but the code is identical, and so are all the properties.

When I present a problem to this forum, I try to remove anything I don't think is germain to the issue. I have 2 reasons for this: 1) I don't want to waste anybody's time trying to understand what my program is about, and 2) I don't want the thread to get off-topic.

If it is necessary, I don't mind at all posting the actual code. When I search for answers before posting questions, I find a lot of posters, on many forums, trying to explain their company's business plan, or internal workings. Some of my posts have gone off-topic when ideas are posted about having my code do something other than what I want. It's MY code, and I'm trying to generate MY "Look and Feel".

Anyway, thanks very much for looking at the problem.

OldBirdman
Jan 23 '08 #3
AlTro
1
@OldBirdman
You wanted an answer in this way? :)
Well, the color of textboxt might be black or white, and the moon might be full or the moon might be new, and form might be modal or not, but it seems that this error tends to happen when form does not allow additions.

I have exactly the same issue, trying to access Text property of textbox in OnChange event, and yes, was getting the same 2185 error.
Long hours of googling finally revealed this Access error 2185 after calling SetFocus and attempting to use the Text property of a Combobox.
So as a workaround you might try to
Expand|Select|Wrap|Line Numbers
  1.  Private Sub txtSearch_Change() 
  2.  Dim wk As String 
  3. Me.AllowAdditions = True
  4.  wk = Me.txtSearch.Text 'This is the statement that gets Runtime Error '2185' 
  5.  . . . 
  6. Me.AllowAdditions = False
  7.  End Sub 
  8.  
Seems it is working for me this way, still testing form behaviors in this case.
However there is a noticeable drawback. Form flickers when it adds and then removes the row for adding data. :(
Feb 28 '09 #4
FishVal
2,653 Expert 2GB
@AlTro
So, why not to put the form within subform control on another form and move that textbox from original place in the form's header/footer to the parent form detail section?
Feb 28 '09 #5
OldBirdman
675 512MB
I am going to stick with the Full Moon idea for my issue. If the AllowAdditions is getting in the way when the form data is empty, then this is a completely different problem. I can see where Access can't give focus to a control bound to nothing. No record, and can't add record, so where is it supposed to be putting the input?

When creating a form that will never have any bound controls, such as my "Filter" form, I routinely set the "Allow ..." to No. I don't know why. My form in one database has 22 textboxes on 13 tabs that are monitored for change, and test the value in .Text.

In the year since I posted this thread, I have discovered a couple of things that may affect focus. If the code window is open, as it usually is in program development, then that window can get the focus. Access is then confused about where the focus should be. Stepping thru code has given different results than having the code run without a breakpoint.

Also, exiting the Sub OnClick ... can affect whether a combobox.dropdown will persist, or not.

I can change the forms Allow Additions to "No", either in design view or VBA. My form works as it should. The fact that I could fix it by creating a new form with ALL the same properties and then re-add this control strongly implies a corruption issue, not a errant property. I never thought to change the data handling properties, as this form and all the controls were unbound.

Sorry FishVal, but I would not make the form more complex as a work-a-round. Not with 22 textboxes.
Feb 28 '09 #6
FishVal
2,653 Expert 2GB
@OldBirdman
I would not too since, as you clearly stated, it was a bug which gone after form rebuilding.
My point was about that reproducible bug with empty recordset / additions not allowed / textbox in form's header combination.
Instead of playing with AllowAdditions property, which causes flicker, the textbox could be moved to another form. Placing the old form within subform event would not change much (if ever at all) interface appearance.

Regards,
Fish.
Feb 28 '09 #7

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

Similar topics

0
by: Paul | last post by:
Hi all, I have developed a system in Access 2000 (SP-3) for a client. The system run's fine on NT 4 and Windows XP and most Win2k machines. I say 'most' Win2k machines because there are a few...
0
by: ann | last post by:
Hi, I am trying to add an ActiveX control on my ASP.NET web form (the language for code behind is C#). I have some client-side vbscript to handle events from the html input buttons. In the...
1
by: patskinny | last post by:
I have a combo box in which a user can select a number of "1" or "0". if the user selects "1" it changes the visible property on other controls that were initial set to "Flase" to "True" . the...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
9
by: Zytan | last post by:
http://msdn2.microsoft.com/en-us/system.windows.forms.control.focus(VS.80).aspx this page says: "Focus is a low-level method intended primarily for custom control authors. Instead, application...
1
by: finditajr | last post by:
Hello I'm having the following problem: My main webpage calls a function stored in a .js file that creates an HTML window to display a calendar. Whenever I click on a date in that calendar,...
3
by: Peachstone | last post by:
I'm using Windows XP and MS Access 2002. I am trying to write code in VB which is attached to a text control on a form called "Scripture1". I have another text control on the same form called...
5
by: Sep410 | last post by:
Hi all, Here is my code: Private Sub Command12_Click() Dim strSql As String strSql = "Delete from tbl_city where CityId=" & Val(Me!txtEmail.Text) & ";" Set cn =...
2
by: Taccat | last post by:
I have a sub form which contains amongst other things 4 textboxes and a disabled button. My goal is that when all 4 text boxes are filled, the button enables, and if one text box is empty, it...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.