Consulting

Results 1 to 3 of 3

Thread: Prog-ly import (replacing) forms

  1. #1

    Unhappy Prog-ly import (replacing) forms

    ... or code, better.

    My data structure is fine, the only further development I'll do is in my forms (natch). I have a form that is admin-only, and on this form I've a button that is supposed to remove all the forms from this database, and then import all the forms from another database.

    The point here is to replace all of the interface and code in one fell swoop. The code to the module looks like this:

    [VBA]
    Private Sub cmdImportForms_Click()
    On Error GoTo cmdImportForms_Err

    ChDrive "S"
    ChDir "\Shared\Project Database\FormImportDB\"

    Dim aryTablesForReimport() As String 'base 0, dynamic array
    Dim dbCurDB, dbFormImportDB As Database
    Dim cntImportedForms As Documents
    Dim filesys
    Set dbFormImportDB = OpenDatabase("FormImport.mdb", , 1)
    Set dbCurDB = CurrentDb
    For Each Item In dbCurDB.Containers(2).Documents
    If Item.Name <> "frmAdmin" Then
    DoCmd.Close acForm, Item.Name, acSaveYes
    End If
    Next
    formi = 0
    'Loop through all forms in FormImport.mdb (at path from above),
    '...and build array made of strings for each form name
    For Each Item In dbFormImportDB.Containers(2).Documents
    'Containers(2) is Forms; stupid watch window, base 0 kids!
    ReDim Preserve aryTablesForReimport(formi)
    aryTablesForReimport(formi) = Item.Name
    formi = formi + 1
    Next

    'Now that we have our array of form names for import,
    'remove all the forms in our active DB (!!), and import the new ones from 'FormImport.mdb
    For i = 0 To UBound(aryTablesForReimport)
    DoCmd.Close acForm, aryTablesForReimport(i), acSaveYes
    DoCmd.DeleteObject acForm, aryTablesForReimport(i)
    DoCmd.TransferDatabase acImport, "Microsoft Access", "FormImport.mdb", _
    acForm, aryTablesForReimport(i), aryTablesForReimport(i), False
    Next i
    'wow. that could be a lot of damage in a few lines of code.
    DoCmd.OpenForm "frmHome"
    GoTo endsub
    cmdImportForms_Err:
    MsgBox Error$ & " " & aryTablesForReimport(formi)
    Resume Next
    endsub:
    End Sub
    [/VBA]

    So, that should be easy enough, right? The customer's data and relationships and everything is preserved, except for the interface; the updated interface is coming from the hard-coded path in the beginning, FormsImport.mdb.

    Very well, then... why isn't it working?

    I'm happy to post the entire database, but it's getting larger (compressed is ~5M now, I think?)

  2. #2
    Hmm, ok, I've edited this just a wee bit now, and now I get a "run-time error '2501', the deleteobject action was canceled" on the DoCmd.DeleteObject line above. What in the world? Why would a DoCmd action get canceled? This is probably going to get complicated, because when I run the macro and debug it while it's running, I get a message to the effect "You can't edit the database now, because you don't have exclusive access to the file." That's a real bummer, and it indicates some much deeper problem with my code here...

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    How is it not working?

Posting Permissions

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