Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2013
    Posts
    18

    Unanswered: Runtime Error 2185, Access 2003

    Hi All,

    Facing issue in below mentioned code.
    Getting Runtime error 2185 on

    "strText = Me.drp_Company.Text"

    Below code is used on combobox drp_company, Query to search company based on the user input.
    Code:
    Private Sub drp_Company_Change()
    Dim strText As String, strFind As String, strSQL As String
    Me.drp_Company.RowSourceType = "Table/Query"
    
    strText = Me.drp_Company.Text
    
    If Len(Trim(strText)) > 1 Then
            strFind = " company_name Like '" & Me.drp_Company.Text & "*'"
            strSQL = "SELECT customer_id, company_name, Country,CMP_STS, company_type, deleted FROM dbo_ACV_customer_sorted WHERE " & _
            strFind & " ORDER BY company_name;"
            Me.drp_Company.RowSource = strSQL
            Me.drp_Company.Dropdown
       End If
    End Sub
    Thanks in Advance.
    Prasanna R.D

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If you read the help you will see that you need to set the focus to that control before trying to reference the text property
    Last edited by healdem; 10-09-15 at 09:38.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2013
    Posts
    18
    Hi healdem,

    Thanks for the reply, as u seen the code, i have applied on Change event, In change event focus will be on the combo box by default.

    Regards,
    Prasanna

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by rd.prasanna View Post
    Hi healdem,

    Thanks for the reply, as u seen the code, i have applied on Change event, In change event focus will be on the combo box by default.

    Regards,
    Prasanna
    if you are hitting error 2185, then clearly your assumption by default doesn't hold ;
    http://answers.microsoft.com/en-us/o...074b2c7?auth=1
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Dec 2013
    Posts
    43
    Provided Answers: 1
    rd,

    You are NOT using the On_Change event of you combo.

    It may look like it, but your Sub doesn't have the arguments that the real On_Change event would.

    Therefore, since your combo doesn't have focus, you can't use the .Text property and get anything meaningful.

    Also, the strText that you are using is a LOCAL variable with no value.

    Turn your sub into the "real" On_Change event and you should be OK.

    Wayne

  6. #6
    Join Date
    Dec 2013
    Posts
    43
    Provided Answers: 1
    rd,

    You are NOT using the On_Change event of you combo.

    It may look like it, but your Sub doesn't have the arguments that the real On_Change event would.

    Therefore, since your combo doesn't have focus, you can't use the .Text property and get anything meaningful.

    Also, the strText that you are using is a LOCAL variable with no value.

    Turn your sub into the "real" On_Change event and you should be OK.

    Wayne

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by WayCal View Post

    You are NOT using the On_Change event of you combo.

    It may look like it, but your Sub doesn't have the arguments that the real On_Change event would.
    Sorry, but the 'real' OnChange event doesn't take any arguments.

    Quote Originally Posted by WayCal View Post

    Therefore, since your combo doesn't have focus, you can't use the .Text property and get anything meaningful.
    If the OnChange event is firing, the Control should have Focus. The only way I can think of that this code would pop an error would be if you weren't actually making a selection, but were Calling the OnChange event from somewhere else in code and the Combobox didn't have Focus.

    Although we usually think of Forms or entire Databases when we speak of corruption, individual Controls, such as Comboboxes, can and do become corrupted. The test and the fix are one and the same; deleting the Control then re-creating it! If it was corrupt, you've verified the fact and solved the problem! If not, you've only lost a minute or two!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •