Hi Jeanette;
As you can see I've made a few minor changes to the creation of the table
you
mentioned but made sure the table name and fields correspond with the
code.
I have a number of tables that should be deleted and replaced when the
field
"tblupdate" and ID are equal. In the table I have ID set to "-1". When
tblupdate (checkbox) is clicked and indicates -1 in the table both fields
are
the same.
Despite this the code is still deleting and replacing all the tables. It
should only delete the tables when ID & tblupdate are equal.
Also the loop continues and is not stopping after going through all the
records.
Thanks for any additional help.
Private Sub Command5_Click()
Dim strFilter As String
Dim strInputFileName As String
Dim Msg As String
Dim db As DAO.Database
Dim rstMain As DAO.Recordset
Dim strtblName As String
On Error GoTo SubErr
strFilter = ahtAddFilterItem(strFilter, "Access File (*.mdb)", "*.mdb")
strInputFileName = ahtCommonFileOpenSave(Filter:=strFilter,
OpenFile:=True,
DialogTitle:="Select RMS Update File...", Flags:=ahtOFN_HIDEREADONLY)
DoCmd.TransferDatabase acImport, "Microsoft Access", strInputFileName,
acTable, "tbl_update", "tbl_update"
Set db = CurrentDb
'Open a recordset on the table tblExportNames
Set rstMain = db.OpenRecordset("tbl_update")
'make sure at start of table
rstMain.MoveFirst
' Use the recordset as a base
With rstMain
' Process until end of file
Do While Not .EOF
'get the name of the table to export
strTableName = rstMain("tblName")
'do the export using strTableName as the object to export etc'
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Certification Type"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Certification Type", "Certification Type"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Training - Course List"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Training - Course List", "Training - Course
List"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "ActivityCodes"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "ActivityCodes ", "ActivityCodes "
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Age"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Age", "Age"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Amount"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Amount", "Amount"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Area"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Area", "Area"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Behavior"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Behavior", "Behavior"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Canines"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Canines", "Canines"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Coordinate Datum"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Coordinate Datum", "Coordinate Datum"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Coordinate Display"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Coordinate Display", "Coordinate Display"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Coordinate Profile"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Coordinate Profile", "Coordinate Profile"
End If
'Delete Detection Type (ID) and Type (Detection ID)'
Dim rels As Relations
Dim rel As Relation
Set rels = CurrentDb.Relations
For Each rel In rels
If rel.Table = Detection Or rel.ForeignTable = "Type" Then
rels.Delete rel.Name
End If
Next rel
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Detection Type"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Detection Type", "Detection Type"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Distance"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Distance", "Distance"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Evidence Recovery Item Searched"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Evidence Recovery Item Searched", "Evidence
Recovery Item Searched"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Evidence Recovery Search Area"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Evidence Recovery Search Area", "Evidence
Recovery Search Area"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Expense Category"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Expense Category", "Expense Category"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Expense Description"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Expense Description", "Expense Description"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Geographic Areas"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Geographic Areas", "Geographic Areas"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Handlers"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Handlers", "Handlers"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Height"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Height", "Height"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Image Library"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Image Library ", "Image Library "
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "IncidentTypes"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "IncidentTypes", "IncidentTypes"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Instructor Contact"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Instructor Contact", "Instructor Contact"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Resource Types"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Resource Types", "Resource Types"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "NameTypes"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "NameTypes", "NameTypes"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Search Results - Incident"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Search Results - Incident", "Search Results -
Incident"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Search Results - Training"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Search Results - Training", "Search Results -
Training"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Search Tactics"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Search Tactics", "Search Tactics"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Special Teams"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Special Teams", "Special Teams"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_activity"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_activity", "st_activity"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_age"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_age", "st_age"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_area"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_area", "st_area"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "St_behavior"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "St_behavior", "St_behavior"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_contamination"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_contamination", "st_contamination"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_location"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_location", "st_location"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_profile"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_profile", "st_profile"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_subject"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_subject", "st_subject"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_time"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_time", "st_time"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_weather"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_weather", "st_weather"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "st_wind"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "st_wind", "st_wind"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "State"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "State", "State"
End If
'Delete Teams (LinkID) and Team Certification/Course History (LinkID)'
For Each rel In rels
If rel.Table = Teams Or rel.ForeignTable = "Team Certification/Course
History" Then
rels.Delete rel.Name
End If
Next rel
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Teams"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Teams", "Teams"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Towns"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Towns", "Towns"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Track Level"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Track Level", "Track Level"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Training Classification"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Training Classification", "Training
Classification"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Training Exercise Codes"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Training Exercise Codes", "Training Exercise
Codes"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Training Location"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Training Location", "Training Location"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Training Profile"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Training Profile", "Training Profile"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "TreatmentCodes"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "TreatmentCodes", "TreatmentCodes"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Type"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Type", "Type"
End If
If ID = tblupdate Then
DoCmd.DeleteObject acTable, "Units"
DoCmd.TransferDatabase acImport, "Microsoft Access",
strInputFileName, acTable, "Units", "Units"
End If
rstMain.MoveNext
Loop
SibExit:
' Destroy the recordset and database objects
rstMain.Close
If Not rstMain Is Nothing Then
Set rstMain = Nothing
End If
If Not db Is Nothing Then
Set db = Nothing
End If
Exit Sub
SubErr:
MsgBox err.Description & " " & err.Number
Resume
End With
Exit Sub
End Sub