Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2006

    Unanswered: Runtime error 2185 when clearing out textboxes

    Hi folks,
    I'm not sure if this is the right place to ask a question regarding VB coding in Access but if it isn't I would really appreciate it if someone could point me to a website/forum where I can ask the following question.
    Basically I am getting the following error :" You can't reference a property or method for a control unless the control has focus."
    I have created a simple form in Access with various command buttons. All I am trying to do is when a user wants to add a new record, they click on the add new record button and it clears out all the text boxes on the form and puts the cursor in the first textbox ready for the user to start entering data. I have put the following code behind the add button and I get the 2185 error......obviously I am missing something ....I have done some VB programming before but not in Access, Here's the code:
    Private Sub cmdNewRecord_Click()

    mblnAdd = True

    End Sub

    Private Sub Empty_FormControls()

    ' Clear Form Controls
    txtBoxNumber.Text = ""
    txtBoxLocation.Text = ""
    txtProjectID.Text = ""
    txtContractID.Text = ""
    txtFRSAccount.Text = ""
    txtTitle.Text = ""
    txtPIlastname.Text = ""
    txtFirstName.Text = ""
    txtMiddleInit.Text = ""
    end sub

    any advice would be very much appreciated

  2. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    You can only use .TEXT if the control has focus. Replace .TEXT with .Value. The .Value property doesn't require the control to have focus.
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    Try setting ".value" instead.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Dec 2002
    Préverenges, Switzerland
    try ignoring the property completely (unless you want to preserve compatibility with the stoneage):
    txtBoxNumber.Text = "" 'requires focus
    txtBoxNumber = "" 'requires reason

    ....bbbbbbut, how did you get into this mess in the first place? who put data there that you don't want?

    i don't live in bound-form-world so i can only worry that we are devloping code here that risks to clear data that we did not intend to clear. doesn't bound-world present an empty record on NEW (apart from table defaults)??

    this bound-world stuff is unneccessary-magic for me so i could be talking crap again.

    currently using SS 2008R2

  5. #5
    Join Date
    Feb 2004
    Chicago, IL
    If your data is bound to your controls then all you need to do is:

    DoCmd.GoToRecord , , acNewRec

    Some side effects of setting all the controls to "":

    1. Any default values that are defined will be overwritten
    2. The new record will automatically have values set, so if the user exits the form and doesn't change anything the data will be saved in the table with blank data. Access's default behavior is to not save a blank record if you merely navigate to a blank record then exit.

Posting Permissions

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