Ms Access Error 2185
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us you cannot reference a property or method for a control unless the control has the focus Learn more about Stack Overflow the company Business Learn more about hiring developers runtime error 424 or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Run time error 2185 up vote 2 down vote favorite I getting a run time error 2185, "You can't reference a property or method for a control unless the control has the focus ...". This is my code that I am using. Private Sub Command5_Click() Dim cardno As Integer cardno = cardnumber.Text DoCmd.OpenForm "search_card_number", acNormal, , WHERE & cardno = [Account Number] End Sub ms-access access-vba share|improve this question edited Dec 20 '13 at 16:30 HansUp 79.3k114371 asked Dec 20 '13 at 12:17 Steve 481211 add a comment| 3 Answers 3 active oldest votes up vote 3 down vote Referencing the .Text property of a control requires it to have focus. Simply drop that and it should work (the default is .Value) OR Try putting in the SetFocus method as advised by Access, i.e. Private Sub Command5_Click() Dim cardno As Integer cardnumber.SetFocus <-------Use this line to set the focus cardno = cardnumber.Text DoCmd.OpenForm "search_card_number", acNormal, , WHERE & cardno = [Account Number] End Sub share|improve this answer answered Dec 20 '13 at 12:35 sonams 1,20741435 I get a runtime error 6, overflow. but the carnumber.text did get the value I was enter in textbox –Steve Dec 20 '13 at 12:42 I guess data can no longer be held by an integer. Try changing the line Dim cardno As Integer to Dim cardno As Long should fix the immediate problem. –sonams Dec 20 '13 at 12:49 I get a 2465 runtime error, and is highlighted the Docmd section in yellow. –Steve Dec 20 '13 at 12:55 add a comment| up vote 1 down vote That run time error mean
be down. Please try the request again. Your cache administrator is webmaster. Generated Thu, 20 Oct 2016 21:13:56 GMT by s_wx1011 (squid/3.5.20)
is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click http://www.dbforums.com/showthread.php?505772-Microsoft-Access-VB-Run-Time-Error-2185 the register link above to proceed. To start viewing messages, select the http://www.dbforums.com/showthread.php?1613032-Runtime-error-2185-when-clearing-out-textboxes forum that you want to visit from the selection below. Results 1 to 2 of 2 Thread: Microsoft Access VB Run Time Error '2185' Tweet Thread Tools Show Printable Version Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode Switch to Hybrid Mode Switch to Threaded ms access Mode 09-16-02,23:19 #1 John316 View Profile View Forum Posts Registered User Join Date Sep 2002 Posts 68 Unanswered: Microsoft Access VB Run Time Error '2185' Question: I have a form with with a text box and when the user enters his information into text box after it saves I want it to automatically add the text ADA-xxxx. I have tried using MS ms access error accesses Build Event and choose "Expression Builder" But I am getting an error. Can Someone please help me??? The Error I am getting is: Microsoft Access Run-time error '2185': "You can't reference a property or method for a control unless the control has the focus. Try one of the following: 1) Move the focus to the control before you reference the property. In Visual Basic code, use the SetFocus method. In a macro, use the GoToControl action. 2) Reference or set the property from a macro or event procedure that runs when the GotFocus event for the Control occurs." My Code is listed below: Private Sub Form_BeforeUpdate(Cancel As Integer) If Left(LABEL_TAG.Text, 4) <> "ADA-" Then LABEL_TAG.Text = "ADA-" & LABEL_TAG.Text End If End Sub Reply With Quote 09-17-02,07:29 #2 nstaward View Profile View Forum Posts Registered User Join Date Aug 2002 Location Cambridge, England Posts 47 Try putting in the SetFocus method as advised by Access, i.e. Private Sub Form_BeforeUpdate(Cancel As Integer) Me.LABEL_TAG.SetFocus If Left(LABEL_TAG.Text, 4) <> "ADA-" Then LABEL_TAG.Text = "ADA-" & LABEL_TAG.Text End If End Sub This should sort the pr
this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 5 of 5 Thread: Runtime error 2185 when clearing out textboxes Tweet Thread Tools Show Printable Version Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 12-19-06,09:28 #1 leedspaddy View Profile View Forum Posts Registered User Join Date Dec 2006 Posts 1 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 txtBoxNumber.SetFocus Empty_FormControls 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 cheers, Patrick Reply With Quote 12-19-06,10:35 #2 Missinglinq View Profile View Forum Posts Moderator Join Date Jun 2005 Location Richmond, Virginia USA Posts 2,763 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 foolproof...is that fools are so darn ingenious! All posts/responses based on Access 2003/2007 Reply With Qu