Error 2185 Results

I keep getting an error:

run-time error '2185'
"you can't reference a property or method for a control unless the control
has the focus."

There is no problem with CheckFilter function, I checked.

My Code:

Quote: Private Sub Building_AfterUpdate()
Call CheckFilter

Dim sBuildingRoom As String
sBuildingRoom = "SELECT DISTINCT Location.[Location ID],Location.Room " & _
"FROM Building INNER JOIN Location ON Building.[Building ID]=Location.[Building ID]" & _
"WHERE Building.[Building Name]= '" & Me.Building.Text & "'" & _
"ORDER by Location.Room"
Me.Location.RowSource = sBuildingRoom

End Sub Thanks

Trying to read the Text in a combobox. The Value (usually an index) is available, but is not always what is needed. Sometimes we want the text.
The Text property is not available unless the control has the focus.
Here is an alternative

Run-time error '2185':
You can't reference a property or method for a control unless the control has the focus.

Read several quetions and feel that this is what people were asking for.
Did not readily find a post that puts the answer up front.
This might help the search.

Immediate Window example:
' combobox- retrieving Values
? Me!id_area.value
? Me!id_area.Text
*** SEE ERROR GENERATED --->>> 2185
Alternate Method
? Me!ID_Area.Column(0)
? Me!ID_Area.Column(1)
ND - Main Store

Note: Column(1) is a contrived value from two or more fields

msgbox "Thank You for choosing " & Me!ID_Area.Column(1), VBOKOnly, "Thanks Bonehead - for purchasing a T-Rex skull"

Also See:

Hi all,

I am trying to adpot this Dynamically search multiple fields into my db from John Big Booty at
w w w.a c c e s s-p r o g r a m m e r

Every thing works great except it gives me run-time error when there's no resault from the search.

The error shows:

Run-Tim error '2185':
you can't reference a property or method for a control unless the control has the focus.

Can anyone help me solve this problem?

Thank you very much.


I'm trying to code a button so that when it is clicked it creates a summary of the data that was entered. The following is my code so far:

Private Sub GenerateSummary_Click()
Dim tempsummary As String

tempsummary = "Requisition generated at the request of" & Director.Text & "via " & Manager.Text & ". ***Position Title:" & Job_Title.Text & "Internal Title:" & VTitle.Text & "."

End Sub


I keep getting the following error:

Run-Time error '2185'

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

My question is:

1. What exactly does this mean?
2. What is the easiest way to fix it?

Run-time error '2185'
You can't reference a property or method for a control unless the control has the focus.

	Private Sub txtName_Change()
    strSaveText = Me.txtName.Text
End Sub

The message occurs for Me.txtName.Text and only if the body of the form contains zero records. What's wrong?

I've searched through the forums for posts regarding Error '2185' (You can't reference a property or method for a control unless the control has the focus.), but can't find anything so far that has helped my situation.


I'm creating an item look-up form with 2 criteria that I wan't to auto-filter as the user types. I'm placing my code in the Change event of the textbox, and only calling the .text for the current textbox (.value or no property at all for the other). The filter works smoothly and as intended until it returns no results in my table, and then it pops me with the error. I've tried forcing focus to the textbox in different places throughout the code, but to no avail. If I use the .value or no property for the current textbox, I'm not getting the CURRENT text, but the old text before it was changed, so the filter doesn't work properly.

Code Snippet:

Private Sub txtVendor_Change()

Me.FilterOn = True
Me.Filter = _
"((strSearchVendor Like '*" & Me.txtVendor.Text & "*' AND strSearchItem LIKE '*" & Me.txtPartNum & "*'))"
Me.txtVendor.SelStart = Len(Me.txtVendor.Text)

End Sub

It usually pops the error on the last line "Len(Me.txtVendor.Text)", but I've had it do it on the Me.Filter line as well (only when debugging and messing with next statement placement).

Any and all help is appreciated.

Hi Guys,

I have a piece of code for a text filter on my form. I am now getting an error "2185, You can't reference a property or method for a control unless the control has focus." The strange thing is that it worked yesterday but not today! In googling people say to remove the .text in my (me.txtfilter.text) but this doesn't appear to work.

Any suggestion would be appreciated.

	Private Sub txtFilter_Change()

    If Nz(Me.txtFilter.Text, "") = "" Then
        Me.FilterOn = False
        Exit Sub
    End If
    Me.txtFilter = "[Second Name] like '" + Me.txtFilter.Text + "%' or [First Name] like '" & _
        Me.txtFilter.Text + "%'"
    Me.FilterOn = True
    Me.txtFilter.SelStart = Len(Nz(Me.txtFilter.Text, "")) + 1

End Sub

Hi guys

I want to transfer the value from a combobox on form3 to textbox on form4 and I am writing the following code for that in form4.But getting this annoying error 2185,can't reference a property or method of a control until it has focus.

	Private Sub Form_Load()
Me.Text6.Value = Forms!form3!Combo19.Text
end sub

Can anyone please help me in this.


Here's the code...

	Private Sub Command53_Click()
    Dim strArcherRef As String
    Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
    Exit Sub
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in ID
    DoCmd.GoToControl ("First")
    DoCmd.FindRecord Me!txtSearch
    strArcherRef = ID.Text
    strSearch = txtSearch.Text
'If matching record found sets focus in ID and shows msgbox
'and clears search control

    If strArcherRef = strSearch Then
        txtSearch = ""
    'If value not found sets focus back to txtSearch and shows msgbox
            MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
            , "Invalid Search Criterion!"
    End If
End Sub

I keep on getting the same error message "Runtime Error '2185': You can't reference a property or method for a control unless the control has focus." on the line of code " strArcherRef = ID.Text". I've spent some good time on this and still can't figure out why. Any ideas?


Hi all!

I have some problems with a search function, or more precise the error-handling of the function.

I’ve added an unbounded textbox (Called search) in the toptext of a continuous form. The form is based on a query which is connected to the unbounded textbox (search).

I’ve written a basic vb function with is activated by the textbox (on change).

	Private Sub search_Change()

        With Me!search
        Dim toSearch As String
        .SelStart = 300
        End With
End Sub

This works well, until there are no more posts to show. Then I get:

Quote: Run-time error ‘2185’ – You can't reference a property or method for a control unless the control has the focus The cause is the .SelStart = 300. Without that line, the Run-time error will not occur. But, the line has to stay..

I’ve tried all the If’s and else’s I know, but could not find a fix. Any ideas?

	Private Sub cboQuickList_Click()
    . . .
    Forms!fAAA.cboQuickList.Visible = True
End Sub

I am clicking the Dropdown list of a combobox. Therefore, it is visible, enabled, and after the click has the focus. The combobox is unbound, and the text portion is still empty, not used. Attempting to set the focus before the requery allows the requery, but then the set focus after the requery fails with "Run-time Error 2110 - Microsoft Access can't move the focus to the control cboQuickList."
Eliminating the second setfocus causes "Run-time Error 2185 - You can't reference a property or method for a control unless the control has the focus." with the .Dropdown statement. "SendKeys {Esc}, True" does various things, but either the errors persist, or the dropdown list does not display.
Stepping through the code is meaningless as the act of stopping the code negates the .Dropdown, and apparently affects the .SetFocus.

I see this error rarely. First there could be absolutely no demonstrable or explicable reason for having such an error... OK now that I am done whining

I quite often make reference to controls when they do not have the focus. However, occasionally this error raises its very ugly head.

I have a text box that contains contents of text file stored on the hard drive, read during the OnCurrent event; which are sql scripts (in a scripts library database). Oftentimes, these scripts are compound or a file containing several select statements. I am attempting to select from the text box then run from an elipsis command button that selected portion. But alas! the infamous 'Cannot reference a property or method or a control without ...' absurdity.

How is this resolved? I am not want to use the MouseUp event or any other internal text box event being too problematic for users.



I try to get the value of a text box which is bounded to an database column of AutoNumber type.

lngID = me![ID].text

I get a run time error 2185, saying that I can't reference the property of a control unless it has focus. But when I try to set focus to that control by


I get run time error 2110, saying that Microsoft Office can't move the focus to that control!

What can I do to get the value of the control?

Thanks in advance.

Hi, I have a popup form that uses a memo field on my form and you can edit/view in a much larger window that on the form.
I am getting a error message when I close the popup form:
Field on Customers form control source (Customer Notes) named (Notes)
Field on form (frmCustomerNotes) is unbound. Name (TxtDescription)

Error message is; Run-time error '2185'
You can't reference a property or method for a control unless the control has the focus.

Private Sub Form_Close()
Forms![Customers]![Customer Notes] = Forms![frmCustomerNotes]![TxtDescription]
TxtDescription.SelStart = Len(Notes) 'HERE IS WHERE CODE ERRORS OUT AT.
End Sub

Private Sub Form_Open(Cancel As Integer)
Forms![frmCustomerNotes]![TxtDescription] = Forms![Customers]![Customer Notes]
End Sub

Hi guys

Sorry but please bear with me. I know its a simple solution but couldn't find out the solution. I have textboxes which store number values. I just want to add them.

Suppose i type 2 in text27 and 8 in text34

	a = Text27.Value + Text34.Value

then it gives me 28 which is wrong.

	a = Val(Text27.Text) + Val(Text34.Text)

then it gives me runtime error 2185 "you cann't reference a property or method of a control unless a control has the focus.

Can anyone please help me


I am trying to assign text to field in the main form. but can't get it to work. I have tried the following. the these error occur.


run time error "2448":
you can not assign a value to this object.


run time error "2185":
You cant referense a property or method for a control unless the control has the focus.


cannot assign the focus to this control

Can any one help. C does work some of the time though

What is wrong with the code below, it keep having "Run-time error '2185': You can't reference a property or method for a control unless the control has the focus."

I just want to calculate the difference of the days with the input txtStartDate.Text & txtEndDate.Text on the form & fill another textbox, txtDaysLeave.Text, with the days difference.

	Private Sub txtEndDate_Change()
    Dim intDays As Integer
    intDays = DateDiff("d", txtStartDate.Text, txtEndDate.Text)
    txtDaysLeave.Text = CStr(intDays)
End Sub

The error happens on the line when I compare the start date(txtStartDate.Text) & end date(txtEndDate.Text).
-> Both are textboxes (however they come with date picker tool when clicked)

These textbox corresponds to date field of my table, Leave_Details.

I've never written true VBA/Access applications before, I've always done a VB front-end to run on top of Access. This application, however, has all the forms done in Access, and I'm just writing the VBA to drive some functions. Specifically, I'm writing the code for a button that will populate a form automatically if a record exists with an indentifying value (in this case, an SSN) that is supplied by the user.

Rather than enter all the info, the user fills in the SSN, clicks 'Fill', and the form populates. Here is the (non-working) code that I have:

	Private Sub Command28_Click()
'This is the code for the Fill button next
'to the Social Security field

'First, make sure an SSN has been entered

If Social_Sec_Num.Value = "" Then
    MsgBox "Please Enter a Socail Security Number", vbOKOnly, "Error"
End If

'We use ControlName.Value instead of .Text to avoid a
'Runtime error 2185 -- ref.

'Then, open the Person table, and retrieve the needed info

Dim dbcn As Connection
Dim rsData As ADODB.Recordset

Set dbcn = New Connection
Set rsData = New ADODB.Recordset

dbcn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=salvation army christmas.mdb;"

Dim strSQL As String
'Need Spouse, Location, Applicant, Person, Income, Dependents
strSQL = "SELECT * FROM tblPerson WHERE [Socail_Sec_Num] = '" & Me.Social_Sec_Num.Value & "';"

rsData.ActiveConnection = dbcn
rsData.Open strSQL

'If no records, display message, end Sub

If rsData.RecordCount = 0 Then
    MsgBox "No Previous Entry for this Applicant"
    Exit Sub
End If

'Fill in appropriate fields

Me.First_Name.Value = rsData("First_Name")
Me.Last_Name.Value = rsData("Last_Name")
Me.Ethnic.Value = rsData("Ethnic")
Me.Birthday.Value = rsData("Birthday")
Me.Middle_Name.Value = rsData("Middle_Name")


End Sub

Do I actually need the Connection/ConnectionString stuff? Can I work with traditional recordsets? Any help would be appriciated.

There a few reasons why I really need to do this programatically, and not with the Wizards that are available. Anyone able to help?

I have a search form that has this code behind below... The problem I'm having is that once I select an option from my ComboBox and an error pops up...
Run-time Error 2185
you cant reference a property or method for a control unless the control has the focus.
I thought in my code I had set the focus on the ComboBox, hovering over the debug line it points to this

	sQRY = _
                "SELECT * " & vbCrLf & _
                "FROM jez.HaH_ReferralReason " & vbCrLf & _
                "WHERE jez.HaH_ReferralReason." & Me.cboSearchOn.Text & " LIKE '*" & Me.txtInputSearch.Text & "*' "

Highlighting the section it shows the error message over the part Me.txtInpustSearch.text. but I've been unable to enter anything in that TextBox as the error has popped up before the opportunity to do so.

	Private Sub txtInputSearch_Change()
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim sQRY As String
'    On Error GoTo Err
    Set cnn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    cnn.Open "Provider=sqloledb;Data Source=CISSQL1;Initial Catalog=CORPINFO;Integrated Security=SSPI;"
    If Not IsNull(cboSearchOn) Then
        If Not IsNull(Me.txtInputSearch.Text) Then
        sQRY = _
                "SELECT * " & vbCrLf & _
                "FROM jez.HaH_ReferralReason " & vbCrLf & _
                "WHERE jez.HaH_ReferralReason." & Me.cboSearchOn.Text & " LIKE '*" & Me.txtInputSearch.Text & "*' "
            rs.CursorLocation = adUseClient
            rs.Open sQRY, cnn, adOpenForwardOnly, adLockReadOnly
            Me.lstSearch.RowSource = sQRY
        End If
    End If
    Set rs = Nothing
    Set cnn = Nothing
    Exit Sub
'    basError.LogError VBA.Err, VBA.Error$, "Form_frmTest- txtInputSearch_Change()"
End Sub

Where am I going wrong?

does anyone else have major issues with this run-time error??

Run-time error '2185':

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

I keep on getting this error unless I put property.setfocus in front of everything.. seems kind of retard and waste of code etc..

for ex.

i'm trying to enable a control when 4 fields have been entered.

Private Sub txt4_AfterUpdate()
If txt1.Text "" And txt2.Text "" And txt3.Text "" Then
cmdGo.Enabled = True
End If
End Sub

problem here is i get that error unless i do this...

Private Sub txt4_AfterUpdate()
If txt1.Text ""then
if txt2.Text "" then.....
if txt3.Text "" Then
cmdGo.Enabled = True
End If
end if
end if
End Sub

one other question: is there a way in access that i can group everything together and refer to it as group1? i can group, btu can't seem to reference it.

last question: is there a way to set txtboxes as part of an array?

thanks for reading this far! thank you veyr much for any help/pointers provided!

Not finding an answer? Try a Google search.