Solved

MS Access VBA progamatially "Write these files to CD"

Posted on 2007-04-11
12
680 Views
Last Modified: 2012-05-05
I'm using access to copy a file from my pc to a CD-R. I can copy the file to ""\Local Settings\Application Data\Microsoft\Cd Burning" using FileCopy, since, for some reason I can't burn it directly to the cd drive (D:\). That works like a charm.

But then it just says that I have files waiting to be burned to the CD. How do I programatically get to the next step; the equivalent to clicking on "File:Write these files to CD"?

I'm assuming it's a SHELL command? Maybe? Anyone?
0
Comment
Question by:StarbuckLives
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 75
ID: 18891942
Battlestar Galactica ?

mx
0
 

Author Comment

by:StarbuckLives
ID: 18891990
Best Drama on TV!
0
 
LVL 75
ID: 18892083
Hummmmm .... well ... '24' ... then BSG ... :-)

btw ....I know the answer off hand ... sorry ... but, ahhh ... could you hook me up with Starbuck ???

mx
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:StarbuckLives
ID: 18892135
My friend... if I had an 'in' with Starbuck, I wouldn't be here trying to figure this out!
0
 
LVL 34

Accepted Solution

by:
jefftwilley earned 500 total points
ID: 18892287
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 18892436
good post Jeff, u can find an example using ICBurn here (no points pls - Jeff posted ICBurn first!) http://www.vbaccelerator.com/home/VB/Code/Libraries/Writing_CDs/Simple_CD_Burn/article.asp (look at the bottom of the page)
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18892437
I found this one too...but I'm websensed..so I couldn't open it

Looks like exactly what You need:
http://www.freedownloadscenter.com/Best/burn-cd-vb_net.html
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18892557
That's a good article Rocki...<<<Adds to Favorites>>>
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 18892581
Well I happen to stumble across that, just so happens u posted ICBurn as well. So u take the credit on this one (thats if ICBurn is used)
0
 

Author Comment

by:StarbuckLives
ID: 18898356
Okay, I'm looking at the code. But how do I apply it to VBA in Access? This is the code I have to copy the file to the "on deck" circle to be burned to CD:

Function fOSUserName() As String

Dim lngLen As Long, lngX As Long
Dim strUserName As String

    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
   
shortname = Left(strUserName, 8)

SourceFileA = "c:\MAPBACKUP\mapbu.zip"
DestinationFileB = "C:\Documents and Settings\" & shortname & "\Local Settings\Application Data\Microsoft\Cd Burning\" & Format(Date, "mmddyy") & "MBU.zip"
FileCopy SourceFileA, DestinationFileB
           
End Function

What code/part of code do I have to add to burn it to the CD?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 18898623
that link I provided had sample code, did u see it?
0
 

Author Comment

by:StarbuckLives
ID: 18898998
I'm sorry, I'm not getting my head around this.  I added this code to the top:

Private Const FAIL_BIT As Long = &H80000000

Private Function FAILED(ByVal hResult As Long) As Boolean
   FAILED = ((hResult And FAIL_BIT) = FAIL_BIT)
End Function

Knowing that we can now instantiate the object:

Private m_cdBurn As ICDBurn

Public Sub Initialise(ByVal hWndOwner As Long)

   ' Set up the CLSID of the Shell Extension which
   ' contains the ICDBurn implementation:
   Dim clsidCDBurn As UUID
   With clsidCDBurn
      .Data1 = &HFBEB8A05
      .Data2 = &HBEEE
      .Data3 = &H4442
      .Data4(0) = &H80
      .Data4(1) = &H4E
      .Data4(2) = &H40
      .Data4(3) = &H9D
      .Data4(4) = &H6C
      .Data4(5) = &H45
      .Data4(6) = &H15
      .Data4(7) = &HE9
   End With

   ' Set up the IID of the ICDBurn interface which
   ' we want to obtain:
   Dim iidCDBurn As UUID
   With iidCDBurn
      .Data1 = &H3D73A659
      .Data2 = &HE5D0
      .Data3 = &H4D42
      .Data4(0) = &HAF
      .Data4(1) = &HC0
      .Data4(2) = &H51
      .Data4(3) = &H21
      .Data4(4) = &HBA
      .Data4(5) = &H42
      .Data4(6) = &H5C
      .Data4(7) = &H8D
   End With
   
   ' Create the instance of the object:
   Dim hr As Long
   hr = CoCreateInstance( _
      clsidCDBurn, Nothing, CLSCTX_INPROC_SERVER, _
      iidCDBurn, m_cdBurn)
   If (FAILED(hr)) Then
      Err.Raise ERR_BASE + 1, App.EXEName & ".cSimpleCDBurner", _
         "Failed to instantiate CDBurn implementation"
   End If
   m_hWndOwner = hWndOwner

End Sub


and I added the bottom code to my function so it looks like this now:

Function fOSUserName() As String

Dim lngLen As Long, lngX As Long
Dim strUserName As String

    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If (lngX > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
   
shortname = Left(strUserName, 8)

SourceFileA = "c:\MAPBACKUP\mapbu.zip"
DestinationFileB = "C:\Documents and Settings\" & shortname & "\Local Settings\Application Data\Microsoft\Cd Burning\" & Format(Date, "mmddyy") & "MBU.zip"
FileCopy SourceFileA, DestinationFileB
           
Private m_cBurn As New cSimpleCDBurner


   Set m_cBurn = New cSimpleCDBurner

   ' Note that the
   m_cBurn.Initialise Me.Hwnd

   ' Get the staging area:
   Dim sStagingArea = m_cBurn.BurnStagingAreaFolder

   ' Copy files and folders to the staging area here

   ' Finally burn the CD
   m_cBurn.Burn

   
End Function

But it says 'Invalid attribute in Sub or Function' and highlights the Private in 'Private m_cBurn As New cSimpleCDBurner' and it doesn't like ' Dim sStagingArea = m_cBurn.BurnStagingAreaFolder'. Should it be:

Dim sStagingArea
sStagingArea = m_cBurn.BurnStagingAreaFolder

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

679 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