Results 1 to 15 of 15
  1. #1
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    34

    Clearing fields and Error 2448

    hello everybody . I have a form used to search records according to different parameters (company name, phone, email, website, etc. ) All the fileds are not associated (see picture)


    Click image for larger version. 

Name:	SearchData.jpg 
Views:	18 
Size:	167.9 KB 
ID:	44966
    The button Pulisci Campi (Clera Fields) is supposed to clear all the fields and has this code:

    Code:
    Private Sub CMDPulisciCampi_Click()    Dim ctl As Control
    For Each ctl In Me.Controls
      If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
         ctl = Null
      End If
    Next
    End Sub
    But the message I get upon clicking is Runtime error 2448: Canno assign value to the object, debugging it goes to
    Code:
    ctl = Null
    It's making me mad. any help?

  2. #2
    Welshgasman is online now Expert
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    654
    ctl.value = Null
    Please, please use # when posting code snippets.
    Cross Posting Etiquette: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



  3. #3
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    34
    Quote Originally Posted by Welshgasman View Post
    ctl.value = Null
    No change, same error...

  4. #4
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,714
    Add a Debug ctl.Name into you loop and see which control is generating the error

    Code:
    Private Sub CMDPulisciCampi_Click()    
    Dim ctl As Control
    For Each ctl In Me.Controls
      If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
        Debug.Print ctl.Name 
        ctl.Value = Null
      End If
    Next 
    End Sub
    
    EDIT: Shouldn't this be

    If ctl.ControlType = acTextBox ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    34
    Quote Originally Posted by Minty;474988

    [CODE
    Private Sub CMDPulisciCampi_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
    Debug.Print ctl.Name
    ctl.Value = Null
    End If
    Next
    End Sub
    [/CODE]

    EDIT: Shouldn't this be

    If ctl.ControlType = acTextBox ?
    same error with
    Code:
    f ctl.ControlType = acTextBox

  6. #6
    Welshgasman is online now Expert
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    654
    So what is the name of the control and what type is it?
    I seem to recall some type of data will not accept a Null?
    Please, please use # when posting code snippets.
    Cross Posting Etiquette: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



  7. #7
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,714
    So which control was it failing on?
    Look in the immediate window (Press ctrl & G in the VBA Editor) and you should see the names of the controls as they are looped through, the last one listed will be the troublesome one.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    34
    Quote Originally Posted by Minty View Post
    So which control was it failing on?
    Look in the immediate window (Press ctrl & G in the VBA Editor) and you should see the names of the controls as they are looped through, the last one listed will be the troublesome one.

    Found, I had put a TxtBox on the copyright in the upper blue part with value:
    Code:
    ="Company Name © 1999 - " & Year(Now())
    and this was the cause of the error. Thanks Minty.
    Is there a way in which I can instruct to skip that TxtBox in clearing the fields, or do I have to change the TxtBox to a label, but losing the automatic year update?

  9. #9
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,714
    You can set the label caption in VBA on form load.
    Use exactly the same formula

    Me.YourLabel.Caption ="Company Name © 1999 - " & Year(Date())
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    34
    Ok Minty perfect, you solved my problem, again thanks!

  11. #11
    Welshgasman is online now Expert
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    654
    For future use, you can also place a value(s) in the tag property of the relevant controls then check for that when amending multiple controls.?
    Please, please use # when posting code snippets.
    Cross Posting Etiquette: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



  12. #12
    Giorgio is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2021
    Posts
    34
    Right Welsgasman, the problem is that the bug was in the copyright field, where I did not remember I had put a TxtBox, not in the daily use fields of the form. Thansk anyway.

  13. #13
    Welshgasman is online now Expert
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    654
    And you would have been unlikely to have put a tag in that control, so the 'bug' would never have occurred, if you had used that method?

    That method is handy for hiding/revealing controls depending on your process. Just offering it up there as an alternative method.?
    Please, please use # when posting code snippets.
    Cross Posting Etiquette: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



  14. #14
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,719
    FWIW, TypeOf...Is is an operator. IIRC it's not even listed in vba - because it's VB. So oddly enough, the control types are not ac constants thus Textbox is correct. I'm with Welshgasman wrt using tags. In this case, I might have put a tag only in textboxes or combos that should be left out of the loop.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  15. #15
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,714
    Quote Originally Posted by Micron View Post
    FWIW, TypeOf...Is is an operator. IIRC it's not even listed in vba - because it's VB. So oddly enough, the control types are not ac constants thus Textbox is correct.
    I never knew that!

    And yes I'd agree about the tag method as well.
    Use it all the time.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. runtime error 2448, can't update this field
    By virgilio in forum Programming
    Replies: 6
    Last Post: 09-16-2020, 03:27 PM
  2. Run-time error: 2448
    By Shadows1989 in forum Forms
    Replies: 10
    Last Post: 11-01-2019, 09:00 AM
  3. Replies: 0
    Last Post: 05-16-2012, 01:48 PM
  4. Error 2448
    By gtrudel in forum Programming
    Replies: 9
    Last Post: 07-11-2011, 07:30 PM
  5. runtime error 2448
    By ds_8805 in forum Forms
    Replies: 3
    Last Post: 04-14-2010, 07:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums