Sub runLoad()
Dim dbs As DAO.Database
Dim dbs2 As DAO.Database
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim distID As String
Dim sql As String
Dim sql2 As String
Dim strRst As String
Dim sourceFile
Dim destinationFile
Dim regid As String
Dim AdminID As String
Dim strName As String
Dim Typ As String
Dim qdf As DAO.QueryDef
Dim qdf2 As DAO.QueryDef
Set dbs = CurrentDb
strRst = "select * from qry_VerifiedLoad where setup = true"
Set rst = dbs.OpenRecordset(strRst)
rst.MoveLast
rst.MoveFirst
DoCmd.Hourglass True
Do Until rst.EOF 'Dists that are checked
regid = rst.Fields("ID")
distID = rst.Fields("OrgID")
AdminID = rst.Fields("AdminID")
strName = rst.Fields("OrgName")
Typ = rst.Fields("Type")
sourceFile = "D:\Documents and Settings\xxxxxxxxxxx\Desktop\statbook_Verified.mdb"
destinationFile = "D:\Documents and Settings\xxxxxxxxxxx\Desktop\LoadVerified\Statbook_Verified_" & AdminID & ".mdb"
Dim strdcty As String
strdcty = destinationFile
If Len(Dir(strdcty)) = 0 Then
FileCopy sourceFile, destinationFile
End If
Dim strLoadExp As String
strLoadExp = "Insert into d_expenditures in '" & destinationFile & "' Select gradeLevCode, ObjCode, ProCode, FunctionCode, Amount, orgID from qry_4_VERIFIED_EXPEND_DONT_OPEN where orgid = '" & distID & "'"
Dim qdfExp As DAO.QueryDef
Set qdfExp = dbs.CreateQueryDef("", strLoadExp)
qdfExp.Execute
Dim strLoadRev As String
strLoadRev = "Insert into d_revenues in '" & destinationFile & "' Select RevCode, ProCode, FLev, Amount, orgID from qry_4_VERIFIED_REV_DONT_OPEN where orgid = '" & distID & "'"
Dim qdfRev As DAO.QueryDef
Set qdfRev = dbs.CreateQueryDef("", strLoadRev)
qdfRev.Execute
Slowdown
'NEED TO UPDATE RECORDS IN C_ORGS 12-14-10
Dim strsqlsetup As String
Dim rstset As DAO.Recordset
Dim setorg As String
strsqlsetup = "Select * from qry_VerifiedLoad where setup = True"
Set rstset = CurrentDb.OpenRecordset(strsqlsetup)
If rstset.RecordCount > 0 Then
rstset.MoveLast
rstset.MoveFirst
Do Until rstset.EOF
setorg = rstset.Fields("OrgID")
sql = "Update c_orgs Set setup = True Where adminid='" & AdminID & "'" CurrentDb.Execute sql, dbFailOnError
rstset.MoveNext
Loop
End If
Dim alset As String
Dim qdfset As DAO.QueryDef
' ALREADYSETUP NEEDS TO BE TRUE OR VERIFIED DB WON'T WORK 9-30-09
alset = "Update c_orgs in '" & destinationFile & "' Set AlreadySetup = True where adminid='" & AdminID & "'"
Set qdfset = dbs.CreateQueryDef("", alset)
qdfset.Execute
sql = "insert into D_Contacts in '" & destinationFile & "' select contact_Name, contact_Phone, contact_Email from D_Contacts where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
Slowdown
sql = "insert into d_stat_edits in '" & destinationFile & "' select * from d_stat_edits where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW1 in '" & destinationFile & "' select * from D_SW1 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW2 in '" & destinationFile & "' select * from D_SW2 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW3 in '" & destinationFile & "' select * from D_SW3 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW4 in '" & destinationFile & "' select * from D_SW4 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW5 in '" & destinationFile & "' select * from D_SW5 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW6 in '" & destinationFile & "' select * from D_SW6 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW7 in '" & destinationFile & "' select * from D_SW7 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW8 in '" & destinationFile & "' select * from D_SW8 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW9 in '" & destinationFile & "' select * from D_SW9 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into D_SW10 in '" & destinationFile & "' select * from D_SW10 where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into tbl_recap_dataentry in '" & destinationFile & "' select * from tbl_recap_dataentry where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into util_opened_exps in '" & destinationFile & "' select * from util_opened_exps where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
sql = "insert into util_opened_revs in '" & destinationFile & "' select * from util_opened_revs where orgid = '" & distID & "'"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
Set dbs2 = DBEngine.Workspaces(0).OpenDatabase(destinationFile)
sql2 = "update d_expenditures in '" & destinationFile & "' set adminid = '" & AdminID & "'"
Set qdf2 = dbs2.CreateQueryDef("", sql)
qdf.Execute
sql2 = "update d_revenues in '" & destinationFile & "' set adminid = '" & AdminID & "'"
Set qdf2 = dbs2.CreateQueryDef("", sql)
qdf.Execute
'POPULATE ALL ADMINIDS 10-15-09
Dim strnoadmin As String
Dim rstnoadmin As DAO.Recordset
strnoadmin = "select * from d_expenditures where IsNull(adminid)"
Set rstnoadmin = CurrentDb.OpenRecordset(strnoadmin)
If rstnoadmin.RecordCount > 0 Then
sql2 = "Update d_expenditures in '" & destinationFile & "' set adminid = '" & AdminID & "'"
Set qdf2 = CurrentDb.CreateQueryDef("", sql2)
qdf2.Execute
End If
Dim strnoadmin1 As String
Dim rstnoadmin1 As DAO.Recordset
strnoadmin1 = "select * from d_revenues where IsNull(adminid)"
Set rstnoadmin1 = CurrentDb.OpenRecordset(strnoadmin1)
If rstnoadmin1.RecordCount > 0 Then
sql2 = "Update d_revenues in '" & destinationFile & "' set adminid = '" & AdminID & "'"
Set qdf2 = CurrentDb.CreateQueryDef("", sql2)
qdf2.Execute
End If
'END OF POPULATE ALL ADMINIDS 10-15-09
sql = "UPDATE c_orgs SET c_orgs.setup = False where Orgid = '" & distID & "'" 'CLEAR OUT c_orgs - SO NEXT RECORD WILL LOAD 1-4-12
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
rst.MoveNext
Loop
DoCmd.Hourglass False
MsgBox ("The district(s) you selected have been loaded.")
sql = "UPDATE c_orgs SET c_orgs.setup = False"
Set qdf = dbs.CreateQueryDef("", sql)
qdf.Execute
End Sub__________________