Flapjacks
04-06-2005, 03:12 PM
... 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:
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
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? :banghead:
I'm happy to post the entire database, but it's getting larger (compressed is ~5M now, I think?)
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:
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
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? :banghead:
I'm happy to post the entire database, but it's getting larger (compressed is ~5M now, I think?)