Getting stuck on my IF and ELSE statments

Hi,

The following code automates the CD burning process from my Access programme.  For some reason when my code gets to

If Not IsNull(Me.cd_burn_date) Then

Open in new window


It skips down to  

Else 'BURN CD AND FINALISE

Open in new window


and misses out

 Else
        'Check if the CD is required to be FINALISED - Does the user need to add to the CD at some stage
        BurnTypeMsg = MsgBox("Will you need to ADD another batch to the CD?", vbYesNo, "Burn Batch")
        If BurnTypeMsg = vbYes Then

        'Create a CD but DO NOT FINALISE
        'Create a CD

Open in new window


onwards.

Here is my full piece of code:

Dim objDiscMaster As IMAPI2.MsftDiscMaster2
  Dim objRecorder As IMAPI2.MsftDiscRecorder2
  Dim DataWriter As IMAPI2.MsftDiscFormat2Data
  Dim intDrvIndex As Integer
  'The Object browser, but not intellisense, presents types for these, but they cannot be used in VBA
  Dim stream As Variant
  Dim FS As Variant
  Dim Result As Variant
  Dim FSI As Object
  Dim strBurnPath As String
  Dim strUniqueID As String
  Dim BurnMsg As Variant
  Dim BurnTypeMsg As Variant
  

  ' *** CD/DVD disc file system types
  Const FsiFileSystemISO9660 = 1
  Const FsiFileSystemJoliet = 2
  Const FsiFileSystemUDF102 = 4
  
  On Error GoTo TestCDWrite_Error
  
'Check Batch is marked as COMPLETE, if not the Burn Process is cancelled

If Me.chk_batch_completed.Value = False Then
MsgBox "This batch is currently not marked as Complete.  You first need to mark the Batch as complete before you can burn a CD", vbInformation, "Not Batch"
Exit Sub
End If

'Check is the Bath has already been marked as BURNED - allow the user to cancel out at this stage
If Not IsNull(Me.cd_burn_date) Then
BurnMsg = MsgBox("A CD for this bacth has already been created.  Do you want to burn another CD?", vbYesNo, "Burn Batch")
    If BurnMsg = vbNo Then
    'Do not create another CD and exit the sub
    Exit Sub
   
    Else
        'Check if the CD is required to be FINALISED - Does the user need to add to the CD at some stage
        BurnTypeMsg = MsgBox("Will you need to ADD another batch to the CD?", vbYesNo, "Burn Batch")
        If BurnTypeMsg = vbYes Then

        'Create a CD but DO NOT FINALISE
        'Create a CD
  
  intDrvIndex = 0
  strBurnPath = Me.batch_output_location
  ' Create a DiscMaster2 object to connect to optical drives.
  Set objDiscMaster = New IMAPI2.MsftDiscMaster2
  
  ' Create a DiscRecorder2 object for the specified burning device.
  Set objRecorder = New IMAPI2.MsftDiscRecorder2
  
  strUniqueID = objDiscMaster.Item(intDrvIndex)
  objRecorder.InitializeDiscRecorder (strUniqueID)

  ' Create a DiscFormat2Data object and set the recorder
  Set DataWriter = New IMAPI2.MsftDiscFormat2Data
  DataWriter.Recorder = objRecorder
  DataWriter.ClientName = "IMAPIv2 TEST"
  'DataWriter.ForceMediaToBeClosed = True
  DataWriter.ForceMediaToBeClosed = False
     
  
  ' Create a new file system image object
  Set FSI = New IMAPI2FS.MsftFileSystemImage
    FSI.VolumeName = Me.cd_reference
    FS = FSI.ChooseImageDefaults(objRecorder)
  

  ' Add the directory and its contents to the file system
  Call MsgBox("Adding " & strBurnPath & " folder to the disc.  Press OK to continue.", vbInformation, "Burn Batch to CD")
  FSI.Root.AddTree strBurnPath, False
  
  ' Create an image from the file system image object
  
  Set Result = FSI.CreateResultImage()
  Set stream = Result.ImageStream
  
  
  ' Write stream to disc using the specified recorder
    Call MsgBox("Please insert a Blank CD or DVD into the tray.  Press OK to continue.", vbInformation, "Burn Batch to CD")
 objRecorder.EjectMedia
  
    Call MsgBox("Burn Batch to disc.  Press OK to continue.", vbInformation, "Burn Batch to CD")
  DataWriter.Write (stream)
    
    Call MsgBox("Burn process completed.", vbInformation, "Burn Batch to CD")
  objRecorder.EjectMedia

  Me.cd_burn_date = Date
            
        End If
    End If
        
Else 'BURN CD AND FINALISE

  intDrvIndex = 0
  strBurnPath = Me.batch_output_location
  ' Create a DiscMaster2 object to connect to optical drives.
  Set objDiscMaster = New IMAPI2.MsftDiscMaster2
  
  ' Create a DiscRecorder2 object for the specified burning device.
  Set objRecorder = New IMAPI2.MsftDiscRecorder2
  
  strUniqueID = objDiscMaster.Item(intDrvIndex)
  objRecorder.InitializeDiscRecorder (strUniqueID)

  ' Create a DiscFormat2Data object and set the recorder
  Set DataWriter = New IMAPI2.MsftDiscFormat2Data
  DataWriter.Recorder = objRecorder
  DataWriter.ClientName = "IMAPIv2 TEST"
  DataWriter.ForceMediaToBeClosed = True
     
  
  ' Create a new file system image object
  Set FSI = New IMAPI2FS.MsftFileSystemImage
    FSI.VolumeName = Me.cd_reference
    FS = FSI.ChooseImageDefaults(objRecorder)
  

  ' Add the directory and its contents to the file system
  Call MsgBox("Adding " & strBurnPath & " folder to the disc.  Press OK to continue.", vbInformation, "Burn Batch to CD")
  FSI.Root.AddTree strBurnPath, False
  
  ' Create an image from the file system image object
  
  Set Result = FSI.CreateResultImage()
  Set stream = Result.ImageStream
  
  
  ' Write stream to disc using the specified recorder
    Call MsgBox("Please insert a Blank CD or DVD into the tray.  Press OK to continue.", vbInformation, "Burn Batch to CD")
 objRecorder.EjectMedia
  
    Call MsgBox("Burn Batch to disc.  Press OK to continue.", vbInformation, "Burn Batch to CD")
  DataWriter.Write (stream)
    
    Call MsgBox("Burn process completed.", vbInformation, "Burn Batch to CD")
  objRecorder.EjectMedia

  Me.cd_burn_date = Date
End If

ExitHere:
  Exit Sub
'Error handling block
TestCDWrite_Error:
  Select Case Err.Number
    Case -1062599674
   MsgBox "Please ensure you have inserted a Blank CD-R or DVD-R Disc", vbCritical, "Batch Lead Sheets : Error"
    Case 94
    MsgBox "You cannot burn a CD without an Output Path.", vbCritical, "Batch Lead Sheets : Error"
   
   Case Else
   MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Batch Lead Sheets : Error"
  End Select
  Resume ExitHere
'End Error handling block

End Sub

Open in new window


I can't quite get my head around the IF and ELSE statements and I think I am tying myself in knots.

The Process i'm trying to achieve is:

1) Check the Batch has been marked as completed
2) If Complete, check if the batch has already been burned
3) If it has been burned ask the user if they would like to burn again (if no, END)
4) If Yes, ask the user if they would like to ADD to the CD (if YES run code 1, if NO run code 2)
5) Update table and EXIT SUB
LVL 1
anthonytrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
you miss the part

Else
        'Check if the CD is required to be FINALISED - Does the user need to add to the CD at some stage
        BurnTypeMsg = MsgBox("Will you need to ADD another batch to the CD?", vbYesNo, "Burn Batch")
        If BurnTypeMsg = vbYes Then

        'Create a CD but DO NOT FINALISE
        'Create a CD

Open in new window

because this belongs to
  If BurnMsg = vbNo Then
            'Do not create another CD and exit the sub
            Exit Sub

Open in new window


not to
If Not IsNull(Me.cd_burn_date) Then

Open in new window

if you want to see it by yourself easily then install Smart Indenter and then go to your module's code (VBE)  and then
Edit -->Smart indent -->Indent module
0
anthonytrAuthor Commented:
Sorry, I'm still none the wiser...
0
PatHartmanCommented:
If you structure the code correctly and indent the levels, you will find it easier to read.  Only ONE path through the nested If is possible.  If a condition is true, it takes the true path.  otherwise, it takes the else path.  It can't take both.  So, if the first condition is true, NOTHING in the Else for that condition would ever be executed.  

Most people indent 4 characters for each level of nesting.  If you have nested more than about 4 levels, you might need to reduce that to 2 or 3 characters (always be consistent).  When the code is formatted neatly, print it out.  On the pieces of paper, draw vertical lines to connect each pair of If else end if's.  That will help you see how the code will be implemented.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anthonytrAuthor Commented:
Thanks to both of you for your assistance.  John: the add-on into VBA is a god-send.  It really does make navigating though IF statments a lot easier.  Pat: Thank you for your advice re printing out the code and going through it methodically.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.