help with formatting!

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
440
Office Version
  1. 2016
Hey guys I have the sub below in access. I am having a lot of trouble getting it to format the cells correctly. For whatever reason it takes the first three columns as general and the rest at dates, which they are cleraly not dates. I belive this export is the last function called that affects the file. I am wondering how can i force access to format each column as a certain format?

for example the file has the header as department and it needs to be a number how can i add that to the below code?

Any help is appreciated!



Private Sub cmdCF_Click()

Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim rst As DAO.Recordset
Dim lngCount As Long
Dim strFName As String, strSheet As String

strFName = txtOut.Value


FileCopy "K:\SHARED\TRANSFER\Enterprise Wide Suspense Initiative\UOT_Combine\M_Templatetest.xlsx", strFName
strSheet = "UOT"

Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open(strFName)
Set xlWS = xlWB.Worksheets(strSheet)
Set rst = CurrentDb.OpenRecordset("qryOutput")

lngCount = rst.RecordCount

If lngCount > 0 Then
rst.MoveLast: rst.MoveFirst
lngCount = rst.RecordCount + 4
End If


xlWS.Range("A2:BU" & lngCount).CopyFromRecordset rst

rst.Close
Set rst = Nothing
xlWB.Close True
objXL.Quit
Set objXL = Nothing

MsgBox "Output File has been created.", vbOKOnly, "Process Complete:"

End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,215,339
Messages
6,124,375
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top