Error Message 2488 (1 Viewer)

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
Hi, I have a form with a series of unbound combo boxes to build a search string in the form header. I also have an unbound combo box 'Username' in the same header. It gets populated with the Username when the form loads. All good.

Problem is when I go to clear the filters with the routine below, I get error message 2448, which I believe is due to the routine unintentionally trying to save a "Null" in Unbound Combo Box 'Username'. I notice this as 'Username' loses it's value upon application of the clear filter button. The code I use is reproduced below. How can I Protect 'Username"' from being overwritten upon clearing of the filters? Appreciate any assistance.

Code:
Private Sub Command26_Click()
    
    'Purpose:   Clear all the search boxes in the Form Header, and show all records again.
    Dim ctl As Control
    
 On Error GoTo ErrorHandler
 
    'Clear all the controls in the Form Header section.
    For Each ctl In Me.Section(acHeader).Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox
                    ctl.Value = Null
        Case acCheckBox
            ctl.Value = False
        End Select
    Next
    
    'Remove the form's filter.
    Me.FilterOn = False
    
ExitError:
    Exit Sub
    
ErrorHandler:
  Select Case Err.Number
    Case 9999
        Resume Next
    Case 999
        Resume Next
    Case Else
        Call LogError(Err.Number, Err.Description, "Filter Off Selection")
        Resume ExitError
    End Select
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:18
Joined
Feb 28, 2001
Messages
26,999
No matter how you cut this, you will need to cheat somehow by providing a marker that your code can check inside that loop.

You could, if this only happens on one form, use the idea of making the control name equal to "UserName" or "txtUserName" or "cboUserName" and then in the loop, check for the control name. OR, if you aren't using the TAG property, put a marker in the .Tag of the control that you want to not be reset. In either case, if you find what you want to leave alone, just don't execute the assignment.

If this is code that would be copied and pasted across multiple forms, you might consider the TAG method - because then you could copy/paste the code across multiple forms. Or you could write a general subroutine to do what you are doing, with the form itself as a formal call parameter.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
The_Doc_Man, I understand the logic but am unclear of the execution! The unbound control is actually called "Username". I'm not familiar with the code required to 'bypass' resetting this control in the loop, but I guess it's an if statement.Without being a pain, could you show me?.I'll remember for next time so I don't get caught again.
 

isladogs

MVP / VIP
Local time
Today, 14:18
Joined
Jan 14, 2017
Messages
18,186
Just need a minor change to the code

Code:
 ...
    'Clear all the controls in the Form Header section.
    For Each ctl In Me.Section(acHeader).Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox
            If Not ctl.Name = "txtUserName" Then ctl.Value = Null
        Case acCheckBox
            ctl.Value = False
        End Select
    Next
...

I would remove the error 999 & 9999 resume next lines
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:18
Joined
May 7, 2009
Messages
19,169
Code:
        Case acTextBox
                    ctl.Value = Null
        Case acComboBox
                    ctl.Value = ""
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
Cheers guys, It's so simple i'm embarrassed! but am learning. Thanks
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
Guys, Isladogs if statement works. Upon resetting the filters the username remains. Fantastic, but I still get error message 2448! I don't know why. I use the following code to capture the username on the top of the header;

Code:
Private Sub Form_Load()
   
    ReSizeForm Me
    Me.[UserName] = Nz("I am Logged in as : " & GetUserName, "")
        
End Sub

Any ideas?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:18
Joined
May 7, 2009
Messages
19,169
check all textboxes and combos, checkbox if there is an Expression on their
ControlSource property, ei.

=some expression.
 

isladogs

MVP / VIP
Local time
Today, 14:18
Joined
Jan 14, 2017
Messages
18,186
First of all it helps if you provide the error description as well as the number
Error 2448 = you can't assign a value to....(object name).
Which object is referenced?

The error is almost certainly because one or more controls is bound to a field so you can't assign a value to it or clear it. Start by checking the referenced object.

Why is user name a combo? That suggest users can change it. Why?

I see your form load event code uses my resizing code and a GetUserName function.
Do bear in mind that whilst I recognise my code, others may not!
What Code are you using in the GetUserName function in case its relevant.
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
Guys, Error message is '2448 : you can't assign a value to this object'. The field in the form header called [Username] is an unbound textbox. This is where the form_load event puts the username captured from the logon screen. I did try trapping the error with the error handler routine by substituting in 'case 2448 resume next'. Clearly this prevents the error message, but this is not preventing the error. Will investigate arnelgp's suggestion too. isladogs, I'll add a comment to my reference to 'resize me' giving credit to you. I'ts the least I can do for your generosity & only proper. Cheers
 

isladogs

MVP / VIP
Local time
Today, 14:18
Joined
Jan 14, 2017
Messages
18,186
Hi
TIA for acknowledgements but that wasn't the point I was making.
What I meant was others may not know what that code line meant or whether it was in any way a cause of your error (it isn't!)

If you are saying the 2448 error is related to an unbound text box containing username then I'm somewhat surprised. How do you assign the username to that textbox? Is the default value GetUserName?
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
isladogs, I removed the text box & the error code still appeared. Thus, the error is not related to that. I use the onload event (see post 7) to propagate the username into the unbound textbox called 'Username' in the header of the form. It seems to work. Is this not correct? 'Getusername' is the name of the routine I call that returns the Username from the logon. There is no default as each user must log on to access this form. Appreciate the prompt response. Next time I shall ensure that I comment any code that I post!!
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 03:18
Joined
Apr 1, 2019
Messages
712
Guys, Found the problem. I could kick myself!. I had both auto_date & auto_time controls on the header! Upon cancelling the filter access was trying to put a "Null" in those values. Hence the error!Sometimes!!!!!!.I have temporarily removed those controls, now all good. How do I modify the if statement to skip over these fields. Is something like this correct:

If Not ctl.Name = ("UserName" or "Auto_Date" or "Auto_Time" )Then ctl.Value = Null

Cheers.
 

Users who are viewing this thread

Top Bottom