Solved

MS Access VBA progamatially "Write these files to CD"

Posted on 2007-04-11
12
679 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

785 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