K
KHogwood-Thompson
I have the following code in a public function that exports a table into
Excel under different tabs derived from the JOBNO field. This works fine on
another database that the JOBNO field contains all numerics, but I am trying
to use the same function in a database where the JOBNO field is prefixed by
two alpha characters "BJ". The result is the the tabs Excel all start with
the character "_" and then the JOBNO. ie for JOBNO BJ5397 the tab shows as
_BJ5397. Does anyone know which parts of the following code needs to be
changed???:
Dim dbD As DAO.Database
Dim rsJOBREF As DAO.Recordset
Dim strFilespec As String
Dim lngJOBREF As String
Dim strSheet As String
Dim strSQL As String
Const SQL1 = "SELECT * INTO [Excel 8.0;HDR=Yes;Database="
Const SQL2 = "FROM COSTSUMMARY WHERE JOBNO = "
Set dbD = CurrentDb()
Set rsJOBREF = dbD.OpenRecordset("SELECT JOBNO FROM COSTSUMMARY GROUP BY
JOBNO" _
, dbOpenSnapshot)
strFilespec = "C:\Cost Summary\New Data.xls"
Do Until rsJOBREF.EOF
'Get JOBREF
lngJOBREF = rsJOBREF.Fields("JOBNO").Value
strSheet = (lngJOBREF)
'Assemble the SQL query to export one jobref
strSQL = SQL1 & strFilespec & ";].[" & strSheet & "] " _
& SQL2 & "'" & lngJOBREF & "'" & ";"
'export it
dbD.Execute strSQL, dbFailOnError
rsJOBREF.MoveNext
Loop
rsJOBREF.Close
End Function
Excel under different tabs derived from the JOBNO field. This works fine on
another database that the JOBNO field contains all numerics, but I am trying
to use the same function in a database where the JOBNO field is prefixed by
two alpha characters "BJ". The result is the the tabs Excel all start with
the character "_" and then the JOBNO. ie for JOBNO BJ5397 the tab shows as
_BJ5397. Does anyone know which parts of the following code needs to be
changed???:
Dim dbD As DAO.Database
Dim rsJOBREF As DAO.Recordset
Dim strFilespec As String
Dim lngJOBREF As String
Dim strSheet As String
Dim strSQL As String
Const SQL1 = "SELECT * INTO [Excel 8.0;HDR=Yes;Database="
Const SQL2 = "FROM COSTSUMMARY WHERE JOBNO = "
Set dbD = CurrentDb()
Set rsJOBREF = dbD.OpenRecordset("SELECT JOBNO FROM COSTSUMMARY GROUP BY
JOBNO" _
, dbOpenSnapshot)
strFilespec = "C:\Cost Summary\New Data.xls"
Do Until rsJOBREF.EOF
'Get JOBREF
lngJOBREF = rsJOBREF.Fields("JOBNO").Value
strSheet = (lngJOBREF)
'Assemble the SQL query to export one jobref
strSQL = SQL1 & strFilespec & ";].[" & strSheet & "] " _
& SQL2 & "'" & lngJOBREF & "'" & ";"
'export it
dbD.Execute strSQL, dbFailOnError
rsJOBREF.MoveNext
Loop
rsJOBREF.Close
End Function