Results 1 to 5 of 5

Thread: ldb file

  1. #1
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I have a situation that I am not able to resolve.

    I have a form that uses a table as its source. If I close the form, but leave the database open, the ldb file on the backend goes away. Perfect! That is what I want, as I want to copy the backend to a new location.

    However, if I close the form in code (see below) it does not release the file and the ldb file is still there. Why would closing the form manually remove the lock, and closing it in code not?

    [codebox]Public Function RentalBackup()
    Dim SourceFile As String
    Dim DestinationFile As String
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String

    ' close the main form before backing up
    DoCmd.Close acForm, "frmRent"

    Set db = CurrentDb
    strSQL = "SELECT BackupDrive, Path, SourceDirectory, FileName " & _
    "FROM tlkpBackupPath " & _
    "WHERE Program='Rental';"


    Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)

    SourceFile = rst!SourceDirectory & rst!FileName
    DestinationFile = rst!BackupDrive & ":" & rst!Path & rst!FileName

    rst.Close
    Set rst = Nothing



    'Copy the source file to the Server Folder
    ' Rental

    FileCopy SourceFile, DestinationFile

    MsgBox "Back up complete"

    End Function[/codebox]

    Any help is greatly appreciated.

    Ken

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    What do you see if you single-step through the code? Does the .ldb file disappear and reappear, or does it remain all the time?

  3. #3
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Even stepping through the code has the same results, that is it doesn't release it.

    And FYI, the lookup table used as the record source in the vb code is a local table within the front end, and not in the backend.

    [quote name='HansV' post='769744' date='08-Apr-2009 11:14']What do you see if you single-step through the code? Does the .ldb file disappear and reappear, or does it remain all the time?[/quote]

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I don't think I can add anything without seeing (stripped down copies of) the frontend and backend.

  5. #5
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Hans,

    Thanks for getting back. I ended up using the following copy the file, as it appear to care about the lock on the file and copies it without getting the permission error. It was posted on "http://www.vbcity.com/forums/topic.asp?tid=132701" by AbbydonKrafts.

    [codebox]Public Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Long
    hNameMappings As Long
    lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS, sets dialog title
    End Type
    Public Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    ' Available Operations
    Public Const FO_COPY = &H2 ' Copy File/Folder
    Public Const FO_DELETE = &H3 ' Delete File/Folder
    Public Const FO_MOVE = &H1 ' Move File/Folder
    Public Const FO_RENAME = &H4 ' Rename File/Folder
    ' Flags
    Public Const FOF_ALLOWUNDO = &H40 ' Allow to undo rename, delete ie sends to recycle bin
    Public Const FOF_FILESONLY = &H80 ' Only allow files
    Public Const FOF_NOCONFIRMATION = &H10 ' No File Delete or Overwrite Confirmation Dialog
    Public Const FOF_SILENT = &H4 ' No copy/move dialog
    Public Const FOF_SIMPLEPROGRESS = &H100 ' Does not display file names

    Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)

    Dim op As SHFILEOPSTRUCT
    With op
    .wFunc = FO_COPY ' Set function
    .pTo = strTarget ' Set new path
    .pFrom = strSource ' Set current path
    .fFlags = FOF_SIMPLEPROGRESS
    End With
    ' Perform operation
    SHFileOperation op

    End Sub


    ' Used the following to call the sub

    Call VBCopyFolder("C:\somepath\filename", "C:\newpath\filename")[/codebox]

    Thanks again for all you do for all of us.

    Ken


    [quote name='HansV' post='769767' date='08-Apr-2009 13:14']I don't think I can add anything without seeing (stripped down copies of) the frontend and backend.[/quote]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •