Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / November 2004

Tip: Looking for answers? Try searching our database.

Run-time error 2185

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DJ - 24 Nov 2004 08:55 GMT
I get an error when I tried to assign the value in a textbox to a variable .
the error says "You can't reference a property or method for a control unless
the control has the focus.

my code is:

Private Sub btnReserve_Click()
Dim DL As String
DL = txtDL.Text                    'retriveing info from text/combo boxes

I'm using Office Access XP
Wayne Morgan - 24 Nov 2004 11:10 GMT
The error is correct, you can't use the Text property unless the control has
the focus. However, you can use the Value property. If the control doesn't
have the focus, the Value and Text property should both contain the same
information if the control is a textbox, for a combo box or listbox there is
another option.

The Value property is the default property, so just removing the ".Text"
should solve your problem for a textbox. For a combo box or listbox, you
need to refer to the Column property if the box is a multi column box. The
Value will come from the Bound Column. If there is only one column, then
this will also be what is displayed in the text portion of the box. If there
is more than one column, frequently the bound column is hidden and is not
the one that is displayed. To get the displayed column, use the Column
property as show below. The index number for the Column property is zero
based, so 0 is the first column, 1 is the second, etc.

> DL = txtDL.Text                    'retrieving info from text/combo boxes
DL = txtDL.Column(1)

You can run into another problem as well if using a Listbox. If you set the
listbox to be a multiselect listbox, you can't just use the Value property.
For that you have to loop through the ItemsSelected collection property of
the listbox to get the index of the selected rows then use the
ItemData(index) property to get the value of each of the selected rows.

Signature

Wayne Morgan
MS Access MVP

>I get an error when I tried to assign the value in a textbox to a variable
>.
[quoted text clipped - 9 lines]
>
> I'm using Office Access XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.