Results 1 to 12 of 12
  1. #1
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    175

    unable to empty text boxes

    The following function works good to make the text boxes visible on my form. But, when I add the line *shown in bold text below) to 'Empty' the values in the text boxes, I get error code 438, object doesn't support this property.



    Code:
    Public Function modMenu_unhideTextBoxes() '   unhides develement text boxes on frmAMainMenu    Dim strBox As String
        
        Dim db As Database
        Dim rst As Recordset
        Set db = DBEngine(0)(0)
        Set rst = db.OpenRecordset("mtQueryMenu", dbOpenDynaset)    '   a table created from a query, containing _
                                                                        the items to make visible and empty the _
                                                                        values in each
                   With rst
                    While Not .EOF
                        strBox = ![fStrTextBoxName]
                        Forms![frmAMainMenu].Controls(strBox).Visible = True
                        Forms![frmAMainMenu].Controls(strBox) = Empty
                        .MoveNext
                    Wend
                End With
        
        rst.Close
        Set rst = Nothing
        Set db = Nothing
    
    
    End Function

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    Looks like 'Empty' is undefined. So,

    Dim Empty as string : Empty = ""

    or just

    Forms!frmAmainMenu.Controls(strBox) = ""

    If you have the line
    'Option Explicit' as the second line of your code module, you would have received a compile time error stating that 'Empty' was an unknown object.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    It ia called a language for a reason.
    You cannot just go and make your own names up without doing something like davegri mentions in post #2
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,122
    Usually it is preferred to use Null instead of zero length string "" so your line will simply become:
    Code:
    Forms!frmAmainMenu.Controls(strBox)=Null
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    "Empty" doesn't seem to be in the list of Access reserved words (although it is a Word reserved word). Yet apparently you can inquire in the immediate window as
    ? Empty = ""
    or
    ? Empty = 0 and both are True. So I don't think I'd use it as a variable, table or field name.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Immediate window is just seeing Empty as a variable, possibly Variant. Can do the same with x:

    ?x = ""
    True

    ?x = 0
    True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    175
    I wasn't trying to make up my own code. "Forms![frmCalendar].Form![tbLineNumber] = Empty" will work. I use 'empty' like that all the time. I just wanted to make "Form![tbLineNumber]" a variable to save lines of code.

    Using
    Code:
    Forms!frmAmainMenu.Controls(strBox) = Null
    Forms!frmAmainMenu.Controls(strBox) = ""
    bothe produce the same error 438 - Object doesn't support this property or method.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    You may be able to eliminate some repetition by assigning an object to a variable, but I don't see how you're going to eliminate lines of code by doing just that. Each line that needs to be written using the full reference will simply need to be written using the variable. One way to avoid repeated referencing is to use a With block for that reference, but that doesn't eliminate the lines you need to act on that referenced thing. If that doesn't help, perhaps post an example of what you have that you are trying to condense.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    If mtQueryMenu contains names of objects that do not have a .value property, such as labels, it will produce the 438 error.

    Still suggest you include 'Option Explicit' in your code modules. 'strBox' is not an explicitly defined object.

  10. #10
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    175
    Ok davegri , you solved it. I did have a label in the table mtQueryMenu. I deleted that object from the table and all methods works, = Empty, = Null, and ="" the same. You also suggested that I
    include 'Option Explicit' in my code. Please tell me what you mean by that.

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    include 'Option Explicit' in my code. Please tell me what you mean by that.
    Lots of examples via google like

    Option Explicit statement (VBA) | Microsoft Learn

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    Quote Originally Posted by lawdy View Post
    I wasn't trying to make up my own code. "Forms![frmCalendar].Form![tbLineNumber] = Empty" will work. I use 'empty' like that all the time. I just wanted to make "Form![tbLineNumber]" a variable to save lines of code.
    Well I would say that is making it up as you go along.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 4
    Last Post: 03-15-2023, 12:27 AM
  2. Replies: 4
    Last Post: 02-21-2014, 01:29 AM
  3. Replies: 3
    Last Post: 04-28-2013, 04:10 PM
  4. Replies: 7
    Last Post: 10-28-2012, 02:55 PM
  5. Replies: 5
    Last Post: 09-02-2011, 03:44 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