Option Compare Database
Dim appExcel As New Excel.Application
Dim xlsheet As Worksheet
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim int_cell As Integer
Public Function TX_Main_Summary()
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TX Summary Top (Export)")
rst.MoveLast
rst.MoveFirst
appExcel.Visible = True
appExcel.Workbooks.Open ("M:\MYPATH\HMDAMAIN.TX.xlt")
ActiveWorkbook.Activate
int_cell = 1
Set xlsheet = ActiveWorkbook.Worksheets("TITLE")
xlsheet.Range("A" & int_cell).Value = Forms![REPORT FORM]!txtTitle
Set xlsheet = ActiveWorkbook.Worksheets("HMDA.TX.")
int_cell = 8
Do While Not rst.EOF
If rst.Fields(0).Value = "AUSTIN" Then
int_cell = 8
Call FILLSHEET
End If
If rst.Fields(0).Value = "DALLAS" Then
int_cell = 9
Call FILLSHEET
End If
If rst.Fields(0).Value = "HOUSTON" Then
int_cell = 10
Call FILLSHEET
End If
If rst.Fields(0).Value = "Fort Worth (Tarrant County)" Then
int_cell = 11
Call FILLSHEET
End If
rst.MoveNext
Loop
Set rst = dbs.OpenRecordset("TX Summary Bottom (Export)")
If rst.RecordCount <> 0 Then
rst.MoveLast
rst.MoveFirst
Do While Not rst.EOF
If rst.Fields(0).Value = "AUSTIN-SAN MARCOS" Then
int_cell = 16
Call FILLSHEET
End If
If rst.Fields(0).Value = "DALLAS-PLANO-IRVING" Then
int_cell = 17
Call FILLSHEET
End If
If rst.Fields(0).Value = "HOUSTON-BAYTOWN-SUGAR LAND" Then
int_cell = 18
Call FILLSHEET
End If
If rst.Fields(0).Value = "FORT WORTH-ARLINGTON" Then
int_cell = 19
Call FILLSHEET
End If
rst.MoveNext
Loop
End If
Set rst = dbs.OpenRecordset("TX MULTIFAMILY Top (Export)")
If rst.RecordCount <> 0 Then
rst.MoveLast
rst.MoveFirst
Do While Not rst.EOF
If rst.Fields(0).Value = "AUSTIN" Then
int_cell = 8
Call FILLSHEET_MULTI
End If
If rst.Fields(0).Value = "DALLAS" Then
int_cell = 9
Call FILLSHEET_MULTI
End If
If rst.Fields(0).Value = "HOUSTON" Then
int_cell = 10
Call FILLSHEET_MULTI
End If
If rst.Fields(0).Value = "Fort Worth (Tarrant County)" Then
int_cell = 11
Call FILLSHEET_MULTI
End If
rst.MoveNext
Loop
End If
Set rst = dbs.OpenRecordset("TX MULTIFAMILY BOTTOM (Export)")
If rst.RecordCount <> 0 Then
rst.MoveLast
rst.MoveFirst
Do While Not rst.EOF
If rst.Fields(0).Value = "AUSTIN-SAN MARCOS" Then
int_cell = 16
Call FILLSHEET_MULTI
End If
If rst.Fields(0).Value = "DALLAS-PLANO-IRVING" Then
int_cell = 17
Call FILLSHEET_MULTI
End If
If rst.Fields(0).Value = "HOUSTON-BAYTOWN-SUGAR LAND" Then
int_cell = 18
Call FILLSHEET_MULTI
End If
If rst.Fields(0).Value = "FORT WORTH-ARLINGTON" Then
int_cell = 19
Call FILLSHEET_MULTI
End If
rst.MoveNext
Loop
End If
xlsheet.SaveAs Forms![REPORT FORM]!txtPath
MsgBox "File has been saved."
Set xlsheet = Nothing
appExcel.Quit
Set appExcel = Nothing
End Function
Public Function FILLSHEET()
xlsheet.Range("B" & int_cell).Value = rst.Fields(1)
xlsheet.Range("C" & int_cell).Value = rst.Fields(2)
xlsheet.Range("D" & int_cell).Value = rst.Fields(3)
xlsheet.Range("E" & int_cell).Value = rst.Fields(4)
xlsheet.Range("F" & int_cell).Value = rst.Fields(5)
xlsheet.Range("G" & int_cell).Value = rst.Fields(6)
End Function
Public Function FILLSHEET_MULTI()
xlsheet.Range("J" & int_cell).Value = rst.Fields(1)
xlsheet.Range("K" & int_cell).Value = rst.Fields(2)
End Function
|