By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,965 Members | 1,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,965 IT Pros & Developers. It's quick & easy.

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

P: 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
  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
Share this Question
Share on Google+
5 Replies

Expert 2.5K+
P: 3,532
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!


is the same as


Linq ;0)>
Oct 7 '08 #2

P: 77
Thank you.It is working now.
Oct 7 '08 #3

Expert 2.5K+
P: 3,532
Glad you got it working!

Linq ;0)>
Oct 7 '08 #4

P: 9
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

Expert 2.5K+
P: 3,532
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

Post your reply

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