Solved Error 2448 Can't assign a value to this object

vanzie

Member
Local time
Today, 04:05
Joined
Aug 23, 2020
Messages
49
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.
 
maybe the control has No Value, so add a blank string:

ctrl = StrConv(ctrl & "", vbUpperCase)
 
maybe the control has No Value, so add a blank string:

ctrl = StrConv(ctrl & "", vbUpperCase)
Still gives me the same error
 
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.
 
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
 
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.
 
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
 
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.
 
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)
 
think we understand that - we are asking what is the name of the control? and what is the value of that control?
 
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
 
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
 
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?
 
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.
 
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.
 
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

Back
Top Bottom