sebble1984
New member
- Local time
- Today, 00:39
- Joined
- Sep 24, 2014
- Messages
- 9
Hi Guys,
I have a report exporting to excel using late binding techniques.
When exported into excel i have numbers for 1,2,3,4 tblPreSiteSurveys.PreSiteSurveyStopTheClockReason entitie and I am trying to either change the numbers here casting from int to string
1 = a
2 = b
looping through the record set, Or i have a blank field in my SQL for the column "P" and adding the formular to that column, but it only goes into the first row of the record set, which is a expandable table.
On Error GoTo Command29_Click_Err
'Utilergy Master Update report
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Dim UserDate As Date
Dim StartDate As Date
Dim EndDate As Date
Dim ForStartDate As Date
Dim ForEndDate As Date
Dim rsCount As Integer
Dim strFormular As String
If IsNull(Me.TxTStartDate.Value) Or IsNull(Me.TxTEndDate.Value) Then
MsgBox "Please Enter Start and End Dates for the Report to be Processed", vbInformation, "Utilergy"
Else
StartDate = Me.TxTStartDate.Value
EndDate = Me.TxTEndDate.Value
ForStartDate = Format(StartDate, "DD/MM/YYYY")
ForEndDate = Format(EndDate, "DD/MM/YYYY")
Dim strSQL As String
strSQL = "SELECT tblProjects.ProjectDateModfied, tblProjects.ProjectNumber, tblWorks.WorkNumber, tblOrders.OrderNumber, autotblProjectStatus.ProjectStatus," & vbCrLf
strSQL = strSQL & "tblWorks.WorkAddressNameNumber & ' ' & tblWorks.WorkAddressStreet & ' ' & tblWorks.WorkAddressTown & ' ' & tblWorks.WorkAddressPostcode, tblProjects.ProjectRecievedDate," & vbCrLf
strSQL = strSQL & "tblPreSiteSurveys.PreSiteSurveyDate, tblProjects.ProjectProvisionalStartDate, tblProjects.ProjectCompletionDate, tblProjects.ProjectActualStartDate," & vbCrLf
strSQL = strSQL & "tblProjects.ProjectActualCompletionDate, tblPreSiteSurveys.PreSiteSurveyStopTheClockDate, tblPreSiteSurveys.PreSiteSurveyStopTheClockCode, tblPreSiteSurveys.PreSiteSurveyStopTheClockReason, ' ' , " & vbCrLf
strSQL = strSQL & "tblPreSiteSurveys.PreSiteSurveyStopTheClockComment, tblWorks.WorkEnergisationDate, tblAsBuiltDetails.AsBuiltDetailsDateSubmittedToENW, tblPreSiteSurveys.PreSiteSurveyContactName," & vbCrLf
strSQL = strSQL & "tblPreSiteSurveys.PreSiteSurveyContactNumber, tblAsBuiltDetails.AsBuiltDetailsDateJointed" & vbCrLf
strSQL = strSQL & "FROM (((tblPreSiteSurveys INNER JOIN (autotblProjectStatus INNER JOIN tblProjects ON autotblProjectStatus.[ProjectStatusID] = tblProjects.[ProjectStatus])" & vbCrLf
strSQL = strSQL & "ON tblPreSiteSurveys.[PreSiteSurveyID] = tblProjects.[FKPreSiteSurveyID]) INNER JOIN tblWorks ON tblProjects.[ProjectID] = tblWorks.[FKProjectID])" & vbCrLf
strSQL = strSQL & "LEFT OUTER JOIN tblAsBuiltDetails ON tblWorks.[WorkID] = tblAsBuiltDetails.[FKWorkID]) INNER JOIN tblOrders ON tblWorks.WorkID = tblOrders.FKWorkID" & vbCrLf
strSQL = strSQL & "WHERE tblProjects.ProjectDateModfied between #" & ForStartDate & "# AND #" & ForEndDate & "# ;"
'counts the number of records for Cell F7 of thhe spreadsheet
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
rsCount = rs.RecordCount
'Start a new workbook in Excel
Dim oApp As Object
Dim oBook As Object
Set oApp = CreateObject("excel.Application")
oApp.Workbooks.Open ("MasterUpdate.xlsm")
oApp.Visible = True
Set oBook = oApp.ActiveWorkbook
Set oSheet = oBook.Worksheets(1)
ForStartDate = Format(StartDate, "DD/MM/YYYY")
ForEndDate = Format(EndDate, "DD/MM/YYYY")
'Add the field names in row 1
' Dim i As Integer
' Dim iNumCols As Integer
' iNumCols = rs.Fields.Count
' For i = 1 To iNumCols
' oSheet.Cells(2, i).Value = rs.Fields(i - 1).Name
' Next
strFormular = "=IF(O3=1,""Weather"","" "")"
'Add the data starting at cell A2
oSheet.Range("A3").CopyFromRecordset rs
oSheet.Range("P3").Formula = strFormular
' oSheet.Range("E13").Value = ForStartDate
' oSheet.Range("E14").Value = ForEndDate
oApp.Visible = True
oApp.UserControl = True
'Close the Database and Recordset
rs.Close
Command29_Click_Exit:
Exit Sub
Command29_Click_Err:
MsgBox Error$
Resume Command29_Click_Exit
End If
Any help or advice would be great thanks. Cheers :banghead:
I have a report exporting to excel using late binding techniques.
When exported into excel i have numbers for 1,2,3,4 tblPreSiteSurveys.PreSiteSurveyStopTheClockReason entitie and I am trying to either change the numbers here casting from int to string
1 = a
2 = b
looping through the record set, Or i have a blank field in my SQL for the column "P" and adding the formular to that column, but it only goes into the first row of the record set, which is a expandable table.
On Error GoTo Command29_Click_Err
'Utilergy Master Update report
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Dim UserDate As Date
Dim StartDate As Date
Dim EndDate As Date
Dim ForStartDate As Date
Dim ForEndDate As Date
Dim rsCount As Integer
Dim strFormular As String
If IsNull(Me.TxTStartDate.Value) Or IsNull(Me.TxTEndDate.Value) Then
MsgBox "Please Enter Start and End Dates for the Report to be Processed", vbInformation, "Utilergy"
Else
StartDate = Me.TxTStartDate.Value
EndDate = Me.TxTEndDate.Value
ForStartDate = Format(StartDate, "DD/MM/YYYY")
ForEndDate = Format(EndDate, "DD/MM/YYYY")
Dim strSQL As String
strSQL = "SELECT tblProjects.ProjectDateModfied, tblProjects.ProjectNumber, tblWorks.WorkNumber, tblOrders.OrderNumber, autotblProjectStatus.ProjectStatus," & vbCrLf
strSQL = strSQL & "tblWorks.WorkAddressNameNumber & ' ' & tblWorks.WorkAddressStreet & ' ' & tblWorks.WorkAddressTown & ' ' & tblWorks.WorkAddressPostcode, tblProjects.ProjectRecievedDate," & vbCrLf
strSQL = strSQL & "tblPreSiteSurveys.PreSiteSurveyDate, tblProjects.ProjectProvisionalStartDate, tblProjects.ProjectCompletionDate, tblProjects.ProjectActualStartDate," & vbCrLf
strSQL = strSQL & "tblProjects.ProjectActualCompletionDate, tblPreSiteSurveys.PreSiteSurveyStopTheClockDate, tblPreSiteSurveys.PreSiteSurveyStopTheClockCode, tblPreSiteSurveys.PreSiteSurveyStopTheClockReason, ' ' , " & vbCrLf
strSQL = strSQL & "tblPreSiteSurveys.PreSiteSurveyStopTheClockComment, tblWorks.WorkEnergisationDate, tblAsBuiltDetails.AsBuiltDetailsDateSubmittedToENW, tblPreSiteSurveys.PreSiteSurveyContactName," & vbCrLf
strSQL = strSQL & "tblPreSiteSurveys.PreSiteSurveyContactNumber, tblAsBuiltDetails.AsBuiltDetailsDateJointed" & vbCrLf
strSQL = strSQL & "FROM (((tblPreSiteSurveys INNER JOIN (autotblProjectStatus INNER JOIN tblProjects ON autotblProjectStatus.[ProjectStatusID] = tblProjects.[ProjectStatus])" & vbCrLf
strSQL = strSQL & "ON tblPreSiteSurveys.[PreSiteSurveyID] = tblProjects.[FKPreSiteSurveyID]) INNER JOIN tblWorks ON tblProjects.[ProjectID] = tblWorks.[FKProjectID])" & vbCrLf
strSQL = strSQL & "LEFT OUTER JOIN tblAsBuiltDetails ON tblWorks.[WorkID] = tblAsBuiltDetails.[FKWorkID]) INNER JOIN tblOrders ON tblWorks.WorkID = tblOrders.FKWorkID" & vbCrLf
strSQL = strSQL & "WHERE tblProjects.ProjectDateModfied between #" & ForStartDate & "# AND #" & ForEndDate & "# ;"
'counts the number of records for Cell F7 of thhe spreadsheet
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
rsCount = rs.RecordCount
'Start a new workbook in Excel
Dim oApp As Object
Dim oBook As Object
Set oApp = CreateObject("excel.Application")
oApp.Workbooks.Open ("MasterUpdate.xlsm")
oApp.Visible = True
Set oBook = oApp.ActiveWorkbook
Set oSheet = oBook.Worksheets(1)
ForStartDate = Format(StartDate, "DD/MM/YYYY")
ForEndDate = Format(EndDate, "DD/MM/YYYY")
'Add the field names in row 1
' Dim i As Integer
' Dim iNumCols As Integer
' iNumCols = rs.Fields.Count
' For i = 1 To iNumCols
' oSheet.Cells(2, i).Value = rs.Fields(i - 1).Name
' Next
strFormular = "=IF(O3=1,""Weather"","" "")"
'Add the data starting at cell A2
oSheet.Range("A3").CopyFromRecordset rs
oSheet.Range("P3").Formula = strFormular
' oSheet.Range("E13").Value = ForStartDate
' oSheet.Range("E14").Value = ForEndDate
oApp.Visible = True
oApp.UserControl = True
'Close the Database and Recordset
rs.Close
Command29_Click_Exit:
Exit Sub
Command29_Click_Err:
MsgBox Error$
Resume Command29_Click_Exit
End If
Any help or advice would be great thanks. Cheers :banghead: