Error 424 - Object required in Access 2016 (1 Viewer)

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
i have a user whose pc has been upgraded to access 2016 and they are the only person out of a group of 300 users who i beleive have now been upgrading and they have started experiencing this error.

I have tracked the error down to some code that i have for snoozing reminders, when access is trying to send a email via outlook.

i have wrote added the code to ignore this error for the time being, but would like to be able to try and understand why this is being logged as a error in 2016.


the code is :
Code:
Sub SnoozeReminders()
On Error GoTo handler
Dim olApp As Object
Dim objRems As Object
Dim objRem As Object
    Set olApp = CreateObject("Outlook.Application")
    Set objRems = olApp.Reminders
    For Each objRem In objRems ' this is the highlighted code when i press debug.
        If objRem.IsVisible = True Then
            objRem.Snooze
        End If
    Next objRem
Exit Sub
handler:
If Err.Number = 424 Then
Resume Next
Else
        Call LogError(Err.Number, Err.Description, "ErrSnoozeReminder", "")
        Exit Sub
End If

End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:15
Joined
Feb 28, 2001
Messages
27,172
First (simple) test: When it does that to you, enter the Debug screen and immediately call up the "Locals" window. Examine/explore the object olApp to see if/how it is defined. Then do the same for objRems. Since those variables are local to this subroutine, they should be in the Locals window.

My first guess is that you got a "silent" error on the CreateObject. However, the method I suggested would confirm or deny that.

Are you aware that you cannot create TWO Outlook application objects? If Outlook is already open, you have to FIND the current app object. I am not sure of the techie reason, but I know from personal experience that it is true.
 

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
Unfortunately i wont be able to log onto the pc that is running 2016 until next week.

I have had a look in the locals window on my pc (Access 2013) but to be honest i am not really sure what i am looking for here.

I can see the olApp, ObjRems and ObjRem, but since i dont know what i am looking for, not sure what looks good, or what would cause the error.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:15
Joined
Feb 28, 2001
Messages
27,172
Tucker - in the Locals window, you should be able to see every item declared in the subroutine or function, whether via DIM, PUBLIC, or PRIVATE declaration. Makes no difference. To the right of the variable name, you will see a data type and/or a value. For the specific case of object variables, you will see Object/Nothing or Object/something. The "something" doesn't really matter. All you need to know is that the object is not Nothing. And that is immediately visible in the window.
 

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
OK, My laptop has now been upgraded to 2016 and i am now seeing the error.
Looking in the locals window, I can see the enclosed.

Objrem - Value - Nothing - Type - Object

is this what you need ? how do i get round this ?

Regards
T61
 

Attachments

  • Capture.JPG
    Capture.JPG
    22 KB · Views: 485

Bilbo_Baggins_Esq

Registered User.
Local time
Yesterday, 20:15
Joined
Jul 5, 2007
Messages
586
Just an idea, but check your project's references and see if the Outlook reference is missing.
Running Access code in a mixed environment can be problematic as the libraries will generally (but not always) update forward but will not update backwards.

Also, just curious why you're not being more descriptive than "as Object" in your definitions?
Try the below instead
Code:
Dim olApp As Outlook.Application
Dim objRems As Outlook.Reminders
Dim objRem As Outlook.Reminder

Set olApp = New Outlook.Application
Set objRems = olApp.Reminders

For Each objRem In objRems ' this is the highlighted code when i press debug.
        If objRem.IsVisible = True Then
            objRem.Snooze
        End If
Next objRem

Set objRems = Nothing
olApp.Quit
Set olApp = Nothing

One thing I've for sure noticed is Office 2016 VBA requires MUCH more literalness and specificity than you could get away with in Office 2010.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:15
Joined
Feb 28, 2001
Messages
27,172
OK, tucker - that is something we needed to see.

You have three objects: olApp, objRems, and objRem. We know that you have done SET statements for olApp and objRems. We know VBA thinks that objRem is Nothing because that is the way of showing uninstantiated objects.

I do find it interesting that even though you declared objRem with a specific object type, it is showing as a generic object when it is Nothing - but that might be an artifact of the formatting routines used by the Locals window.

Tracking this backwards, the For Each syntax looks good, so what is in objRems? It is obviously supposed to be a collection, but is it perhaps empty?

At the time when you take that error and open the Locals window, you can click on the PLUS sign next to objRems to expand it and see how many objects are in it. You will see other properties listed, but you need to see how many Reminder objects are exposed when you expand objRems.

If you have at least ONE extant Reminder in the collection, then you've got me stumped. But if the collection is empty, your correction would be to test objRems.Count for being 0 before you attempt the For Each loop.

Just as a side note: In that routine, you created a new Outlook app. In a test system that works. But in production, that might fail because Outlook doesn't allow two copies of itself to exist. If the user had Outlook open for another purpose, you would have trouble. Then, you do the olApp.Quit, which would fail if the "New Outlook" creation failed. So the code you showed us isn't free from peril.
 

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
Hi both, thanks for the advice so far, I tried the above code provided by Bilbo_Baggins_Esq and get a error message. "Compile error. User Defined type not defined" the following code is highighted.

Code:
Dim olApp As Outlook.Application

I have attached additional screenshots of the objrems locals window (i do not know how to export these).
Sorry to appear thick but i am new to the locals window and not really sure what bit to look at so hope i have provided enough information.
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    16.1 KB · Views: 512
  • Capture2.JPG
    Capture2.JPG
    55.8 KB · Views: 275
  • Capture3.JPG
    Capture3.JPG
    35.9 KB · Views: 239

Bilbo_Baggins_Esq

Registered User.
Local time
Yesterday, 20:15
Joined
Jul 5, 2007
Messages
586
Hi both, thanks for the advice so far, I tried the above code provided by Bilbo_Baggins_Esq and get a error message. "Compile error. User Defined type not defined" the following code is highighted.

Code:
Dim olApp As Outlook.Application

I have attached additional screenshots of the objrems locals window (i do not know how to export these).
Sorry to appear thick but i am new to the locals window and not really sure what bit to look at so hope i have provided enough information.

That error means it isn't seeing the Outlook Library.

Check your project's references.
Tools > References

Look first to see if there is a listing for:
Microsoft Office (version) Object Library (MISSING)
If there is, it'll be near t the top.
If there is, make note of the version number

12.0 = Office 2007
14.0 = Office 2010
15.0 = Office 2013
16.0 = Office 2016

If it has a version number different than the Office you have installed, leave it unchecked and scroll down further and locate and check Microsoft Outlook (your version) Object Library has a check.
 

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
I checked the references and nothing was highlighted as missing. (Pic enclosed)

I did not previously have a tick in the Microsoft Outlook Object Library, so i have now put a tick in that box and now getting error 424 Object Required at the Line
Code:
Set olApp = New Outlook.Application

When i hover over this i get Outlook.Application. <Object Variable or With Block Variable not set>
 

Attachments

  • Capture4.JPG
    Capture4.JPG
    35.3 KB · Views: 320

Bilbo_Baggins_Esq

Registered User.
Local time
Yesterday, 20:15
Joined
Jul 5, 2007
Messages
586
I checked the references and nothing was highlighted as missing. (Pic enclosed)

I did not previously have a tick in the Microsoft Outlook Object Library, so i have now put a tick in that box and now getting error 424 Object Required at the Line
Code:
Set olApp = New Outlook.Application

When i hover over this i get Outlook.Application. <Object Variable or With Block Variable not set>

Can you please post the full current code you have?
 

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
Code:
Dim olApp As Outlook.Application
Dim objRems As Outlook.Reminders
Dim objRem As Outlook.Reminder

Set olApp = New Outlook.Application
Set objRems = olApp.Reminders

For Each objRem In objRems 
        If objRem.IsVisible = True Then
            objRem.Snooze
        End If
Next objRem

Set objRems = Nothing
olApp.Quit
Set olApp = Nothing
 

Bilbo_Baggins_Esq

Registered User.
Local time
Yesterday, 20:15
Joined
Jul 5, 2007
Messages
586
Code:
Dim olApp As Outlook.Application
Dim objRems As Outlook.Reminders
Dim objRem As Outlook.Reminder

Set olApp = New Outlook.Application
Set objRems = olApp.Reminders

For Each objRem In objRems 
        If objRem.IsVisible = True Then
            objRem.Snooze
        End If
Next objRem

Set objRems = Nothing
olApp.Quit
Set olApp = Nothing

Ok, there is clearly something we're not seeing in other code somewhere.
I just pasted that EXACT code (directly copy pasted from your last post) in a blank sub in a clean Access Module and set the proper Outlook reference and it runs perfectly. NO ERRORS

Try this.
Create a blank, clean, fresh Access database (or even an Excel workbook).
Open the Visual Basic editor and insert a module.
Paste the below code in it and set the proper Outlook reference.
Then run the code.

Code:
Sub OlRemTest()
'requires reference to Microsoft Outlook (version) Object Library

Dim olApp As Outlook.Application
Dim objRems As Outlook.Reminders
Dim objRem As Outlook.Reminder

Set olApp = New Outlook.Application
Set objRems = olApp.Reminders

MsgBox objRems.Count

If objRems.Count > 0 Then
    For Each objRem In objRems
        If objRem.IsVisible = True Then
            objRem.Snooze
        End If
    Next objRem
End If

Set objRems = Nothing
olApp.Quit
Set olApp = Nothing

End Sub
 

tucker61

Registered User.
Local time
Yesterday, 18:15
Joined
Jan 13, 2008
Messages
321
Done, in new database, no other Modules in DB.
I get a Error on
Code:
Dim olApp As Outlook.Application
 

Attachments

  • Capture5.jpg
    Capture5.jpg
    88.9 KB · Views: 381

Bilbo_Baggins_Esq

Registered User.
Local time
Yesterday, 20:15
Joined
Jul 5, 2007
Messages
586
Done, in new database, no other Modules in DB.
I get a Error on
Code:
Dim olApp As Outlook.Application

In your screen shot, there is no reference check for the Microsoft Outlook (16.0) Object Library.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:15
Joined
Feb 28, 2001
Messages
27,172
OK, let's simplify this and do a form of late binding. Change this:

Code:
Dim olApp As Outlook.Application

to

Code:
Dim olApp As Object

Do the same for objRems.

If you declare those two items as generic objects, it is similar to declaring a variant variable. It can be anything but doesn't know what it is until you actually set a value. Well, here I'm suggesting that you just have generic object holders that will become instantiated as a specific object type only after you execute the subsequent SET statements.

You SHOULD be able to leave the declaration of objRem (no s) as-is. I have no idea why you can't to this but other members have been able to do it, so I'm shooting for a quick-and-dirty work-around to get you moving again.

If it works, it won't tell you or us why your current method didn't work, but of course if it works, you can proceed to do other things.
 

Orthodox Dave

Home Developer
Local time
Today, 02:15
Joined
Apr 13, 2017
Messages
218
Your attachment doesn't include the Outlook object library. I've attached mine for comparison.
 

Attachments

  • Capture.JPG
    Capture.JPG
    60.2 KB · Views: 242

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:15
Joined
Feb 28, 2001
Messages
27,172
Good catch, Dave. I missed that in the image. He's got Office but not Outlook.

B.B.E. - if you don't have the Outlook library, that will cause the "Dim" statements to be all messed up, right off the bat.
 

Users who are viewing this thread

Top Bottom