Results 1 to 4 of 4
  1. #1
    RJ45 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    2

    Run-time Error - Compile Error: Syntax Error

    Disclaimer: I'm not an Access or VB guy, at all. I'm trying to troubleshoot a database for a client and I really have no idea what I'm looking at. With that said...

    I'm trying to change the date entry for a record and I keep getting a Run-time Error.

    Specific error below:


    Run-time error '-2147221233 (8004010f)':
    The attempted operation failed. An object could not be found.

    I click the DEBUG button and get the line in red highlighted.

    Code:
    Private Sub eraseapp(dateapp As Date, subjectapp As String)
    
    Dim strFind
    Dim objAppt1
    Dim olappointment As Outlook.AppointmentItem
      'Using object rather than MailItem, so that it
      'can handle posts, meeting requests, etc as well
      
      Dim olExp As Outlook.Explorer
      Dim calendarFolder As Outlook.MAPIFolder
      'Dim olApp As Outlook.Application
      Dim colCalendar
      
      
      'Set olApp = Outlook.CreateObject("Outlook.Application")
      If Not InitializeOutlook Or olApp Is Nothing Then
        MsgBox "There was an error initializating outlook"
      Else 'if it is not able to initalizate outlook it will not create the appointment
        Set olExp = olApp.ActiveExplorer
        Set calendarFolder = olApp.GetNamespace("MAPI").Folders("Public Folders").Folders("All Public Folders").Folders("Bid Calendar")
        'Set calendarFolder = olApp.GetNamespace("MAPI").GetDefaultFolder(9)
        Set colCalendar = calendarFolder.Items
        
        strFind = "[AllDayEvent] = True And " & "[Start] = " & Quote(FormatDateTime(dateapp, vbShortDate) & " " & FormatDateTime(dateapp, vbShortTime)) & " and [Subject] = " & Quote(subjectapp)
    
    
        'MsgBox strFind
        Set objAppt1 = colCalendar.Find(strFind)
        If Not objAppt1 Is Nothing Then 'if find the appointment that is changing delete it
            objAppt1.Delete
        End If 'if it does not find the appointment we dont have to worry because it is already gone
        Set olappointment = Nothing
        Set calendarFolder = Nothing
        Set objApp1 = Nothing
      End If
    End Sub
    Then, I close the debugger window and attempt the date change again and it brings me directly the code snippet below with the "Compile Error: Syntax Error" message:

    Code:
    Private Sub creacita()  
      Dim olappointment As Outlook.AppointmentItem
      'Using object rather than MailItem, so that it
      'can handle posts, meeting requests, etc as well
      
      Dim olExp As Outlook.Explorer
      Dim calendarFolder As Outlook.MAPIFolder
      'Dim olApp As Outlook.Application
    
    
      
      'Set olApp = Outlook.CreateObject("Outlook.Application")
      If Not InitializeOutlook Or olApp Is Nothing Then
        MsgBox "There was an error initializating outlook"
      Else 'if it is not able to initalizate outlook it will not create the appointment
        Set olExp = olApp.ActiveExplorer
        Set calendar    'Set calendarFolder = olApp.GetNamespace("MAPI").GetDefaultFolder(9)
        Set olappointment = calendarFolder.Items.Add("IPM.Appointment")
        With olappointment
            .Start = [bid date]
            .AllDayEvent = True
            .Subject = ProjectName & "---" & Estimator
            .BusyStatus = olFree
            .Save
        End With
        Set olappointment = Nothing
        Set calendarFolder = Nothing
      End If
      
    End Sub

    Any advice would be appreciated. Thanks!

    Peace,
    Aaron

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What did the code look like before you started messing with it?

    Someone has commented out the statement where the variable OLAPP is defined as an outlook object so any time you reference it it's going to bomb out. If this worked at some point that's the most glaring issue.

    you can try uncommenting the line

    SET olAPP = outlook.createobject("outlook.application")

    but you will definitely have to set the variable up as well with

    dim olApp

    if you intend to use the variable in your code

  3. #3
    RJ45 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    2
    The code isn't mine. The code was written years ago, and now, anyone who has knowledge of how to do anything with the code is gone fro the company. This is what the code has looked like since the first time I saw it. I didn't change anything in the code.

    About a week ago the database was upgraded from Access 2003 to Access 2010, and up until a couple days ago, the lady who adds and changes records had been able to make the necessary date changes.

    I'm reluctant to make any changes myself, but I'll see what I can do tomorrow and post an update. Thanks.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If you still have copy of the 2003 version of the database, open that up (preferably on a machine that is still running access2003) and look at the references it's using for the code. In the code window it should be in the toolbar (tools>references I think) It may be that during the conversion the references the database was using were changed or MS access didn't know which reference to point to in the newer version and you'll have to find the correct reference for the MAPI controls.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  5. Compile Error Syntax Error
    By Mohamed in forum Access
    Replies: 3
    Last Post: 10-06-2011, 10:12 AM

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