0

I'm using Access 2010 and I'm rusty as heck... So I create a main form and an unbound subform. Unbound to the main form, I should say, but bound to a record source. Things work fine.

In the subform, I have a dropdown called cboGIReqNbr with IDs in it. I also have a textbox called txtGIReqNbr. What's supposed to happen is that when you choose a cboGIReqNbr from the dropdown, txtGIReqNbr is supposed to populate with the description.

I've got this in the AfterUpdate event of cboGIReqNbr:

Dim db As Database
Dim rec As Recordset
Dim sSql As String

Set db = CurrentDb

sSql = "Select GI_Request_Name from tblGIRequest where GI_Request_Nbr = '" & Me.cboGIReqNbr.Text & "'"

Set rec = db.OpenRecordset(sSql)

Me!txtGIReqNbr.SetFocus

Me!txtGIReqNbr.Text = rec(0)  <-- PROBLEM

Me.txtLanID = Forms!frmHoursAssigned.cboEmployee.Value

rec(0) does, in fact, populate with the correct text.

The error I get on the problem line is; "This property is read-only and can't be set". None of my objects should be read-only, and all the examples I could find online pointed to people using reserved words (i.e. using "Name" as a field name).

Anyone know how to solve this?

Erik A
  • 31,639
  • 12
  • 42
  • 67
Johnny Bones
  • 8,786
  • 7
  • 52
  • 117

1 Answers1

3

You should use the .Value property to assign values to a text box. .Text changes the visible value and can only be used when the field has focus. .Value stores the actual value and can be used at any time.

Me!txtGIReqNbr.Value = rec(0)

Also see: Distinction between using .text and .value in VBA Access

Erik A
  • 31,639
  • 12
  • 42
  • 67
  • Then I get a "You can't assign a value to this object" error. Is it because the subform is linked to a table, and the textbox is bound to a field in the table? – Johnny Bones Dec 04 '17 at 18:22
  • If the table is writeable, and the textbox's control source is a field, not an expression, that shouldn't matter. Can you change the content of the textbox by hand (just click on it and type something)? If the field is bound to something that's not updateable, that explains it, and you could unbind it. – Erik A Dec 04 '17 at 18:27
  • Ugh. Yeah, that worked (had to unbind it) but my form is a continuous form and now the value is identical in every txtGIReqNbr. Oh well, that's a different question. Thanks for your help! – Johnny Bones Dec 04 '17 at 18:49