Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Reference Property unless Control has the focus...??? 2

Status
Not open for further replies.

sanders720

Programmer
Aug 2, 2001
421
0
0
US
This just seems sop simple. I have one line of code when I click on a combo box. This is supposed to place a value of "1" in a corresponding textbox.

It looks like this...

me.txtITJobNo.Text="1"

and produces this error...

Runtime Error 2185 - You can't reference a property or method unless the control has the focus.


So...Just for fun, I added a setfocus to the textbox prior to trying to change the textbox, which looks like this...

me.txtITJobNo.SetFocus
me.txtITJobNo.Text="1"

which produces this error...

Runtime Error 2115 - The Macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Microsoft Access from saving the data in the field.


I don't follow. There is no BeforeUpdate code for either the combo box or the text box, and I don't know what is meant by ValidationRule.

Any thoughts, and thanks in advance...

 
if you are trying to alter what is displayed in the text box then use the .value property instead of .text

simon
 
Okay, I used .Value instead of .Text and it worked, but what;'s the difference? I guess I've always wondered why there's two controls for the same thing...

Now, I am trying to populate the same way with a variable, and it can't find the object...

B1(q).Value = "2"

This happens with either .Value or .Text... The B1(q) evaluates properly... Thanks in advance for any help you can provide...


Private Sub BUILDQUERY2()

Dim c As Integer
Dim q As Integer

B1 = Array("txtITJobNo", "txtVendor", "txtInvoiceNo", "txtRequestingUser", "txtAuthorizingUser", "txtPurchaseDate", _
"txtWarrantyDate", "txtManufacturer", "txtName", "txtPartNo", "txtSerialNo", "txtCDKey", _
"txtUpgrade", "txtQuantity", "txtSeats", "txtUser", "txtInstalledPC", "txtLicense", _
"txtPurchasedPrice")

For q = 1 To 19
If B(q) <> &quot;&quot; And B1(q) <> &quot;2&quot; Then
c = c + 1
If Len(OBJECT2) > 0 Then
OBJECT2 = OBJECT2 & &quot; and (&quot; & A(q) & &quot;= '&quot; & B(q) & &quot;'.Text)&quot;
Else
OBJECT2 = &quot;(&quot; & A(q) & &quot;= '&quot; & B(q) & &quot;'.Text)&quot;
End If
Debug.Print OBJECT2

B1(q).Value = &quot;2&quot;
B(q).Enabled = False

End If

Next q

End Sub
 
i'm not sure why value works and not text property. text property is used in visual basic and there isn't a value property.

if B1 holds the names of the controls you wish to access then instead of using B1(q) to access the control you should be able to use:

forms(&quot;formname&quot;)(B1(q)).value = &quot;2&quot;

if this function is written within the form then you could also use:

me(B1(q)).value = &quot;2&quot;

&quot;me&quot; is just a short way of referring to the form you are in.

simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top