wrightyrx7
Registered User.
- Local time
- Today, 13:53
- Joined
- Sep 4, 2014
- Messages
- 104
Hi all,
I use the code below to copy data from a subform to Excel.
However, some of the dates are coming out "mm/dd/yyyy" instead of "dd/mm/yyyy" (not all of them though). Is there a way to make sure they all come out "dd/mm/yyyy"?
Thanks in advance.
I use the code below to copy data from a subform to Excel.
However, some of the dates are coming out "mm/dd/yyyy" instead of "dd/mm/yyyy" (not all of them though). Is there a way to make sure they all come out "dd/mm/yyyy"?
Thanks in advance.
Code:
Private Sub cmdExport_Click()
'*******************************************
'**********EXPORT TO EXCEL BUTTON***********
'*******************************************
Me.[tblDetails subform].SetFocus 'line 1: Selects the subform
Me.[tblDetails subform]![CaseID].SetFocus 'Line 2: sets the focus in the first field/record in the subform
DoCmd.RunCommand acCmdSelectAllRecords 'Select all the records-ie including filtred records
DoCmd.RunCommand acCmdCopy 'Copy the selected record
Me.cboEmpID.SetFocus
Dim xlapp As Object
Set xlapp = CreateObject("Excel.Application") 'create an excel application object
With xlapp
.Workbooks.Add 'add new workbook in the excel
[COLOR="Red"] .activesheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:=False ' Line 10[/COLOR]
'Line 10: paste the copied records,not as a link please
.Cells.HorizontalAlignment = -4131
.Cells.Rows.AutoFit
.Selection.AutoFilter
.Cells.Columns.AutoFit
'***************************************************************************************
'Now loop through the rows starting from row 1 to 19 which is A1 to S1 and apply formating as below
Dim i As Integer
For i = 1 To 12
.Cells(1, i).Font.Bold = True
.Cells(1, i).Font.ColorIndex = 3
.Cells(1, i).Interior.ColorIndex = 37
Next 'end of loop
'****************************************************************************************
.Worksheets(1).Cells(2, 2).Activate ' make cell B2 as the active cell
.ActiveWindow.FreezePanes = True 'Now freezepanes from the active cell B2
.Visible = True
.Range("a1").SELECT 'If for some reason if other cells are selected please select A1 as am now done.
End With
export_Click_Exit:
Exit Sub
export_Click_Err:
MsgBox Error$
Resume export_Click_Exit
End Sub