Results 1 to 7 of 7
  1. #1
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98

    Option Box - Error "Object Required"

    I have 2 option boxes. One captioned "Run macro after export" and named "runmacro". And the 2nd captioned "Yesterday" and named "yestsel". I am trying to run a simple script to say
    Code:
    if runmacro.checked = true then
    or
    Code:
    if yestsel.checked = true then
    but I keep getting errors saying "Object required" or "Object does not support this property or method"
    Here is my actual code:



    Code:
    Function ChosenOptions()
    
    If runmacro.Checked = True Then
    
    
        runmacexp = True
        
    End If
    
    
    If yestsel.Checked = True Then
    
    
         fromdate.Value = "Date()-1" And todate.Value = "Date()-1"
    
    
    End If
        
    End Function

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    It should be
    Code:
    Date -1
    in both cases

    .Value is not needed as that is the default

    I also recommend using Me. prefix e.g Me.fromdate

    What is 'runmacexp?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    Still errors if I use the "me" prefix.

    runmacexp is a boolean for an if-statement to let access know to run an excel macro after export.

    Click image for larger version. 

Name:	test.PNG 
Views:	11 
Size:	16.5 KB 
ID:	33174

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    To use the me. predicate the code needs to be in a form module. The error message implies it is in a standard module.

    Also there is no such property as checked, and because it is has a Boolean value it will be true or false anyway

    all you should need is

    if me.runmacro then

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Apologies re Me.
    With hindsight I should have checked whether this was part of a form module.

    Also recommend you add the line Option Explicit as the second line in each module.
    Then check the project compiles and if not fix all errors
    That would have picked up the .checked error that I missed.
    Tick 'Require Variable Declaration in the VBE Options to do this automatically for all future modules
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    To clarify more of the backstory; I have to use a module in order to call some variables I am wanting to be global. So I am using those option box names in the module rather than the form module. EDIT: As I was typing this, I think I figured out my solution: Move the function to the form module and call it from there.

  7. #7
    schulzy175 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    98
    I will be marking this thread as solved. I ended up switching to checkboxes instead since they seem easier to implement at the moment. Thanks for all the help!

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

Similar Threads

  1. Need help to resolve - Error appears "Object Required"
    By awaiskazmi in forum Programming
    Replies: 4
    Last Post: 10-30-2017, 10:45 PM
  2. Replies: 3
    Last Post: 07-12-2017, 04:29 PM
  3. Replies: 7
    Last Post: 07-10-2015, 01:02 PM
  4. Replies: 3
    Last Post: 02-06-2015, 03:22 PM
  5. Replies: 1
    Last Post: 03-14-2013, 12:39 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