Set Unbound TextBox OnCurrent - Run-time 2448 Error (1 Viewer)

misscrf

Registered User.
Local time
Today, 05:52
Joined
Nov 1, 2004
Messages
158
I have the following onCurrent code, for a form, so I can set 2 unbound text boxes to create a dynamic string, for the user. The code checks if the form is on a new record. If so, it makes the 2 unbound text boxes be blank, so they don't show #Name errors. That is what you see, if none of the pieces that are used in the formulas for the text boxes, have any value to them.

I get an error, when I try to load the form. It loads on the last record, which means it's not a new record.

Code:
Private Sub Form_Current()
    If Me.NewRecord Then
        Me.txtBox1.Value = ""
        Me.txtBox2.Value = ""
    Else
        Me.txtBox1.Value = DLookup("MyType", "tblMyType", "ID= " & Nz([FKMyType], 0)) & " " & DLookup("MyCategory", "tblMyCategory", "ID= " & Nz([FKMyCategory], 0)) & " " & Nz([MyLocation], 0)
        Me.txtBox2.Value = "ABC" & Format([ID], "0000")
    End If
End Sub

Error:
run-time error '2448': you can't assign a value to this object

Anyone know what I'm doing wrong?
 

Ranman256

Well-known member
Local time
Today, 05:52
Joined
Apr 9, 2015
Messages
4,337
dont use: Me.txtBox2.Value
just use: Me.txtBox2 = ""

I assign these all the time
 

misscrf

Registered User.
Local time
Today, 05:52
Joined
Nov 1, 2004
Messages
158
I changed a couple of things around, including your suggestion and now the error says:

run-time error '-2147352567 (80020009)': you can't assign a value to this object

This is how I changed the code:

Code:
Private Sub Form_Current()
    Dim Mytxt1 As String
    Dim Mytxt2 As String
    If Me.NewRecord Then
        Mytxt1 = ""
        Mytxt2 = ""
    Else
        Mytxt1 = DLookup("MyType", "tblMyType", "ID= " & Nz([FKMyType], 0)) & " " & DLookup("MyCategory", "tblMyCategory", "ID= " & Nz([FKMyCategory], 0)) & " " & Nz([MyLocation], 0)
        Mytxt2 = "ABC" & Format([ID], "0000")
    End If
    
    Me.txtBox1 = Mytxt1
    Me.txtBox2 = Mytxt2
    Me.txtBox1.Requery
    Me.txtBox2.Requery
    
End Sub

I had made the last part say:

Code:
 Me.txtBox1.ControlSource = Mytxt1
 Me.txtBox2.ControlSource = Mytxt2
 Me.txtBox1.Requery
 Me.txtBox2.Requery

and that didn't result in a pop-up error, but did make the textboxes say #Name?

:-(
 

isladogs

MVP / VIP
Local time
Today, 10:52
Joined
Jan 14, 2017
Messages
18,246
Are you SURE its an inbound textbox.
Normally that error occurs when you try and set a value to a BOUND textbox
 

misscrf

Registered User.
Local time
Today, 05:52
Joined
Nov 1, 2004
Messages
158
omg that was it. I had each textbox control set to their formulas, to start, so they did have a control source, which meant they weren't technically unbound text boxes. I cleared them out, and now it's good! Thank you!!!!!
 

isladogs

MVP / VIP
Local time
Today, 10:52
Joined
Jan 14, 2017
Messages
18,246
You're welcome.
I've done that myself
 

Users who are viewing this thread

Top Bottom