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

Run-time error '2185' You can't reference a property or method

77
Hi all,

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command12_Click()
  2. Dim strSql As String
  3.        strSql = "Delete from tbl_city where CityId=" & Val(Me!txtEmail.Text) & ";"
  4.     Set cn = CurrentProject.Connection
  5.     cn.Execute strSql
  6.  
  7.     Debug.Print "MyTableView created"
  8.     Set cn = Nothing
  9. End Sub
I get the Run-time error '2185' when I run it.


You can't reference a property or method for a control unless the control has the focus .!!!!!!!

If I put this line after defending of the strsql everything work well but I don't want to have this line in my code.
Expand|Select|Wrap|Line Numbers
  1. ' Me!txtEmail.SetFocus
There are some SQL statements which has 2 conditions I can't set the focus for both of them at the same time.
Oct 7 '08 #1
5 18642
missinglinq
3,532 Expert 2GB
In Access VBA the Text property is only available when the control has focus, as you've seen .The Text property is seldom used in VBA. Use the .Value Property instead. It doesn't require focus to work. And since it's the Default Property for a textbox/combobox, you don't actually have to include it!

txtEmail

is the same as

txtEmail.Value

Linq ;0)>
Oct 7 '08 #2
Sep410
77
Thank you.It is working now.
Oct 7 '08 #3
missinglinq
3,532 Expert 2GB
Glad you got it working!

Linq ;0)>
Oct 7 '08 #4
I had a couple of textboxes I needed to change the .text property on, but when I would setfocus to update the textbox it would cause problems by activating all my events I had placed on those textboxes. It allows me to change the values without causing events to trigger.

Sir Devo
Nov 12 '09 #5
missinglinq
3,532 Expert 2GB
As I said previously, there is seldom any reason to use the Text Property in Access VBA, and it certainly shouldn't be used to set value of a textbox! If you need to change the value of a textbox thru code, use the Value Property, which doesn't require setting the focus to the textbox.

Me.TextboxName.Value = "Whatever"

Since the Value Property is the default property for textboxes, comboboxes, etc., you can simply use

Me.TextboxName = "Whatever"

omitting the .Value.

Welcome to Bytes!

Linq ;0)>
Nov 12 '09 #6

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

Similar topics

4
by: SiuLoBow | last post by:
Hi, Is there anyway to detect the ActiveX control is able to run on the browser or not? After I installed the ActiveX control to my system, user sometimes switch the secruity setting to "not...
2
by: Jenna Olson | last post by:
Hi all- I've never seen this particular issue addressed, but was wondering if there's anything to support one way or another. Say I have a class: class ManipulateData { public:...
7
by: erniedude | last post by:
Hi, I'm a newbie and I was wondering if anyone knew a (Python) script to run 4 batch files, one after the other (assuming the directories are known). It would be better if all 4 batch files...
5
by: Thomas | last post by:
I am using php 5.0.4 under IIS 6 under Windows Server 2003 and want to run a php-script as a separate process. This schript dies not have any output. I tried several variants without success: ...
5
by: nephish | last post by:
hey there all, i have been looking for a way to run a php command line script from my python script. here is what i want to do: if x = 4: execute php4 testin.php else: execute php4...
8
by: Tim | last post by:
Is it possible to close the form I invoked via Application.Run() as I invoke another form without the application exiting? (I'd rather not hide it since I don't need it anymore) ....call to...
10
by: Woody Splawn | last post by:
I have been developing a ClientServer application on one machine at my office but the time has come to transfer it to the customer. The customer is running a Windows 2000 local area network. I...
28
by: | last post by:
I have a multi threaded windows form application that runs great after calling Application.Run(). Application.Run is required for a COM component I a using in the app (required for message loop). ...
0
by: modularmix | last post by:
Does anyone know how to run the Excel Macro for two different spreadsheets in parallel. Here is the code that works sequentially. Workbooks.Open Filename:="C:\Documents and...
1
by: GaryDean | last post by:
We have a new server2003 machine that was built like all the rest - IIS and everything needed to run asp.net apps. We have a test asp.net website that we use for new machines to make sure...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.