Solved

Object Variable Not Set

Posted on 2010-08-20
10
525 Views
Last Modified: 2013-11-28
I have a form that opens a powerpoint file after selecting "Get Presentation 1" button.  Then when you're done you take a quiz and go to "Get Presentation 2" button.  ("Get Presentation 2" button opens another form).  Everything works fine up to this point.  After "Get Presentation 2" opens the vba code doesn't recognize the buttons for "First Slide", "Next Slide", etc etc.  I get the error "Object variable or With block variable not set".  The error occurs on the "mcolSlideIDs." verbiage.  I have also attached the zip access file.  Also, If there are any suggestions of a better way to ask/store questions/answers to powerpoint slides I'd love to hear them (because I think this is going to be a little slow).
Option Explicit
Option Compare Database

' Initialize variables.
Private mcolSlideIDs As Collection
Private mlngSlideIndex As Long

Private Sub SetSlide(ByVal ID As Integer)
    On Error GoTo ErrorHandler
    
    ' Open PowerPoint
    Dim strPowerPointFile As String
    Dim pptobj As PowerPoint.Application
    Set pptobj = New PowerPoint.Application
    pptobj.Visible = True
    pptobj.WindowState = ppWindowMinimized
    
'Message here to wait
    Form_frmWait.Visible = True
    
    strPowerPointFile = CurrentProject.Path & "\Forecasting2.ppt"
    
    'With strPowerPointFile.Visible = True
    '    Set mcolSlideIDs = New Collection
    '    Dim ppSlide As PowerPoint.Slide
    '    For Each ppSlide In .Slides
    '        mcolSlideIDs.Add ppSlide.SlideID
    '    Next
    '    .Close
    'End With
'*****
     ' Close PowerPoint
    pptobj.Quit
    Set pptobj = Nothing
    
    ' Make object frame visible and enable "navigation" buttons.
    insertShow.Visible = True
    pptFrame.Visible = True
    frstSlide.Enabled = True
    lastSlide.Enabled = True
    nextSlide.Enabled = True
    previousSlide.Enabled = True
    cmdForecastingQuiz1.Enabled = True
    'cmdClose.Enabled = True
    cmdForecastingPresentationPart3.Enabled = True
Form_frmWait.Visible = False

    ' Specify OLE Class, Type, SourceDoc, SourceItem and other properties.
    With pptFrame
        .Class = "Microsoft Powerpoint Slide"
        .OLETypeAllowed = acOLELinked
        .SourceDoc = strPowerPointFile
    End With
    SetSlide 1
    
    frstSlide.SetFocus
    insertShow.Enabled = False
    
    
     With strPowerPointFile.Visible = True
        Set mcolSlideIDs = New Collection
        Dim ppSlide As PowerPoint.Slide
        For Each ppSlide In .Slides
            mcolSlideIDs.Add ppSlide.SlideID
        Next
        .Close
    End With
   
    Exit Sub
'*****
    Select Case ID
    Case Is > mcolSlideIDs.Count
        MsgBox "This is the last slide."
    Case 0
        MsgBox "This is the first slide."
    Case Else
        mlngSlideIndex = ID
        With pptFrame
            .SourceItem = mcolSlideIDs(mlngSlideIndex)
            .Action = acOLECreateLink
        End With
    End Select

    Exit Sub
ErrorHandler:
    MsgBox Err.Number & " " & Err.Description
    Exit Sub
End Sub

Private Sub frstSlide_Click()
    SetSlide 1
End Sub
Private Sub lastSlide_Click()
    SetSlide mcolSlideIDs.Count
End Sub

Private Sub nextSlide_Click()
    SetSlide mlngSlideIndex + 1
End Sub

Private Sub previousSlide_Click()
    SetSlide mlngSlideIndex - 1
End Sub

Private Sub cmdForecastingQuiz2_Click()
On Error GoTo Err_cmdForecastingQuiz2_Click
    
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmForecasting_Q2"
    
    Form_frmForecasting_Q2.Visible = True
          
Exit_cmdForecastingQuiz2_Click:
    Exit Sub

Err_cmdForecastingQuiz2_Click:
    MsgBox Err.Description
    Resume Exit_cmdForecastingQuiz2_Click
    
End Sub

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


    DoCmd.Close
    DoCmd.Close
Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click
    
End Sub
Private Sub cmdForecastingPresentationPart3_Click()
On Error GoTo Err_cmdForecastingPresentationPart3_Click
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim strPowerPointFile As String
    Dim pptobj As PowerPoint.Application
    
    
    stDocName = "Form_frmForecastingPresentation3"
        
    Form_frmForecastingPresentation3.Visible = True
    Form_frmForecastingPresentation2.Visible = False
    
        ' Open PowerPoint

    Set pptobj = New PowerPoint.Application
    pptobj.Visible = True
    pptobj.WindowState = ppWindowMinimized
    
'Message here to wait
    Form_frmWait.Visible = True
    
    strPowerPointFile = CurrentProject.Path & "\Forecasting3.ppt"
    
    ' Fill a collection with all Slide IDs.
    With pptobj.Presentations.Open(strPowerPointFile)
        Set mcolSlideIDs = New Collection
        Dim ppSlide As PowerPoint.Slide
        For Each ppSlide In .Slides
            mcolSlideIDs.Add ppSlide.SlideID
        Next
        .Close
    End With
    
    ' Close PowerPoint
    pptobj.Quit
    Set pptobj = Nothing

    ' Make object frame visible and enable "navigation" buttons.
    Form_frmForecastingPresentation3.pptFrame.Visible = True
    Form_frmForecastingPresentation3.frstSlide.Enabled = True
    Form_frmForecastingPresentation3.lastSlide.Enabled = True
    Form_frmForecastingPresentation3.nextSlide.Enabled = True
    Form_frmForecastingPresentation3.previousSlide.Enabled = True
    Form_frmForecastingPresentation3.cmdForecastingQ3a.Enabled = True
    'cmdClose.Enabled = True
    Form_frmForecastingPresentation3.cmdForecastingPresentationPart4.Enabled = True
Form_frmWait.Visible = False
    
    ' Specify OLE Class, Type, SourceDoc, SourceItem and other properties.
    With Form_frmForecastingPresentation3.pptFrame
        .Class = "Microsoft Powerpoint Slide"
        .OLETypeAllowed = acOLELinked
        .SourceDoc = strPowerPointFile
    End With
    SetSlide 1
    
    Form_frmForecastingPresentation3.frstSlide.SetFocus
    cmdForecastingPresentationPart3.Enabled = False
                      
Exit_cmdForecastingPresentationPart3_Click:
    Exit Sub

Err_cmdForecastingPresentationPart3_Click:
    MsgBox Err.Description
    Resume Exit_cmdForecastingPresentationPart3_Click
    
End Sub

Open in new window

Forecasting.zip
0
Comment
Question by:BCTITech
  • 4
  • 4
  • 2
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33487447
from the VBA window, do a DEBUG>Compile

correct any errors raised
0
 

Author Comment

by:BCTITech
ID: 33487494
I did that..that's when I get the same message "Object variable or With block variable not set".  
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33487805
BCTITech,
there are so many errors in the codes in the form "frmForecastingPresentation2" module.

the codes in your form "frmForecastingPresentation1" works, so just pattern the codes of form frmForecastingPresentation2 in the codes from form "frmForecastingPresentation1"


0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:BCTITech
ID: 33487987
I'll give it a try...however, form2 has a few different functions to perform than form1.  Thank you for the input.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33488016
<.however, form2 has a few different functions to perform than form1>

copy first the code that the function of the form are the same, test the codes.
if working properly, start adding the other functionalities
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33488197
Basically this error means that you created an Object, but you did not SET it to anything
Ex:
Dim rst as dao.recordset
'SET rst=currentDB.openrecordset ("Sometable")


Or that you declared it, set it, ...but somewhere along the line Unset it (Set SomeObject=Nothing), then tried to use it again.

So check your code for something like this as well.

;-)

JeffCoachman

0
 

Author Comment

by:BCTITech
ID: 33488677
Thank you....I'll look it over this weekend & see if I can find out where I changed SetFocus.
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 250 total points
ID: 33488712
?
I said:
See where you may have forgotten to "SET" the object (not SetFocus)

Jeff
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 33491532
BCTITech,
test this....
several lines of codes were revised

this does not show the error you are getting..

so you can proceed to whatever you need to add to your application..

if you have any problem not related to the error you posted, just open another thread..
eWFMTraining.mdb
0
 

Author Closing Comment

by:BCTITech
ID: 33500762
Thanks for the tips!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to run a VBS file in a MS access macro? 2 28
Can not open the Access Help ? 3 53
sql statement - 9 24
unable to create table-based data macro in MS ACCESS 2013 11 23
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now