Solved Error 2448 Can't assign a value to this object (1 Viewer)

vanzie

Member
Local time
Today, 16:11
Joined
Aug 23, 2020
Messages
45
Hi everyone

My code:
Code:
Dim ctrl As Control
For Each ctrl In Detail.Controls
    If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox) Then
        ctrl = StrConv(ctrl, vbUpperCase)
    End If
Next

This code is fired upon clicking the Save button in my form and is the first code in the line. All other codes follow after. In all my other forms, this code executes as I want it but in this specific form, it gives me the 2448 error. My form is an unbound form and consists of saving a person's information such as names, address, date of birth etc.

I've checked my table and all fields in the form but I cannot find the fault.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:11
Joined
May 7, 2009
Messages
19,230
maybe the control has No Value, so add a blank string:

ctrl = StrConv(ctrl & "", vbUpperCase)
 

vanzie

Member
Local time
Today, 16:11
Joined
Aug 23, 2020
Messages
45
maybe the control has No Value, so add a blank string:

ctrl = StrConv(ctrl & "", vbUpperCase)
Still gives me the same error
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:11
Joined
May 7, 2009
Messages
19,230
hmm, can you check if there are controls (tbox, combo) that have
Expression as their ControlSource, like:

=someExpression

or there are controls that are Locked.
 

vanzie

Member
Local time
Today, 16:11
Joined
Aug 23, 2020
Messages
45
There is one control yes that has the expression to display the age from the DOB value but the age value does not save to the table
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:11
Joined
Sep 21, 2011
Messages
14,238
And if you walk through your code, you will likely find it balks on that control.
If a control has an expression, you cannot assign anything to it.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:11
Joined
Feb 19, 2013
Messages
16,610
have you stepped through the code to see if it is happening with every control or just one

edit: beaten too it:)

just put debug.print ctrl.name before your strconv line
 

vanzie

Member
Local time
Today, 16:11
Joined
Aug 23, 2020
Messages
45
And if you walk through your code, you will likely find it balks on that control.
If a control has an expression, you cannot assign anything to it.
But now I don't understand is that I've gone through another database I designed and the exact method I used there, is used in this one. Same age display textbox with the expression and it saves perfectly without error.
 

vanzie

Member
Local time
Today, 16:11
Joined
Aug 23, 2020
Messages
45
have you stepped through the code to see if it is happening with every control or just one

edit: beaten too it:)
When it shows me the error and I click debug, it highlights this part:
Code:
ctrl = StrConv(ctrl, vbUpperCase)

same with @arnelgp code:
Code:
ctrl = StrConv(ctrl & "", vbUpperCase)
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:11
Joined
Feb 19, 2013
Messages
16,610
think we understand that - we are asking what is the name of the control? and what is the value of that control?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:11
Joined
May 7, 2009
Messages
19,230
so exclude the Age textbox:
Code:
Dim ctrl As Control
For Each ctrl In Detail.Controls
    If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox) Then
        If Left$(ctrl.ControlSource & "", 1) = "=" Or ctrl.Locked Then
        Else
            ctrl = StrConv(ctrl & "", vbUpperCase)
        End If
    End If
Next
 

vanzie

Member
Local time
Today, 16:11
Joined
Aug 23, 2020
Messages
45
so exclude the Age textbox:
Code:
Dim ctrl As Control
For Each ctrl In Detail.Controls
    If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox) Then
        If Left$(ctrl.ControlSource & "", 1) = "=" Or ctrl.Locked Then
        Else
            ctrl = StrConv(ctrl & "", vbUpperCase)
        End If
    End If
Next

That works perfectly. Thank you
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:11
Joined
Sep 21, 2011
Messages
14,238
so exclude the Age textbox:
Code:
Dim ctrl As Control
For Each ctrl In Detail.Controls
    If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox) Then
        If Left$(ctrl.ControlSource & "", 1) = "=" Or ctrl.Locked Then
        Else
            ctrl = StrConv(ctrl & "", vbUpperCase)
        End If
    End If
Next
I thought Locked was just for the user interface?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:11
Joined
May 7, 2009
Messages
19,230
I thought Locked was just for the user interface?
if the control is Locked, you can't assign value to it.
error will occur if you try.
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:11
Joined
Sep 21, 2011
Messages
14,238
if the control is Locked, you can't assign value to it.
error will occur if you try.
Sorry Arnel, I would beg to differ (well in 2007 at least).
I locked a control, and was still able to set a value within code.? I did this after my post to see for myself. Bound or Unbound?
However there was not any expression in the control source.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:11
Joined
May 7, 2009
Messages
19,230
Sorry Arnel, I would beg to differ (well in 2007 at least).
i tested it and you are correct.
so it is safe to remove it from the code.
 

Users who are viewing this thread

Top Bottom