S
simon
Hi, need help with following code, it work great. But after export to excel
the Nums column show only none sequence number from 1 to.100 which was
created when input new customer, and sort by Customer Last and First name by
query.
How do I add a LineCustNo in a form [fCustomer] with a subform [Custdetails]
and need to have a LineCustNo on each record for the Customer details.
All help is greatly appreciated as I have spent 2 weeks with this already.
Private Sub btnExportCust_Click()
Dim db As Database, rs As Recordset
Dim I As Integer, j As Integer
Dim RsSql As String
Dim IssueField As Variant
Dim Workbook As Object
Dim xlApp As Object
Dim mysheet As Object
Set db = CurrentDb()
Dim stLinkCriteria As String
stLinkCriteria = "[TripID]=" & Me![TripID]
RsSql = "SELECT * FROM [qCust] where " & stLinkCriteria & ";"
Set rs = db.OpenRecordset(RsSql, DB_OPEN_DYNASET)
Set xlApp = CreateObject("Excel.Application")
Set mysheet = xlApp.Workbooks.Open("D:\TMS\CustList.xlt").Sheets("Sheet1")
'-------------
j = 6
Do Until rs.EOF
mysheet.Cells(j, 1).Value = rs!Nums
mysheet.Cells(j, 2).Value = rs!CustLastFirstName
rs.MoveNext
j = j + 1
Loop
If mysheet.Cells(35, 2).Value = "" Then
mysheet.PageSetup.PrintArea = "A1:F34"
Else
mysheet.PageSetup.PrintArea = "A1:F63"
End If
'****** Get the filename ********
Dim strFileSpec As String
strFileSpec = "D:\TMS\CustList-" & Format([T_S_Date], "yymmdd") ".xls"
mysheet.Parent.SaveAs strFileSpec
xlApp.Visible = True
End Sub
the Nums column show only none sequence number from 1 to.100 which was
created when input new customer, and sort by Customer Last and First name by
query.
How do I add a LineCustNo in a form [fCustomer] with a subform [Custdetails]
and need to have a LineCustNo on each record for the Customer details.
All help is greatly appreciated as I have spent 2 weeks with this already.
Private Sub btnExportCust_Click()
Dim db As Database, rs As Recordset
Dim I As Integer, j As Integer
Dim RsSql As String
Dim IssueField As Variant
Dim Workbook As Object
Dim xlApp As Object
Dim mysheet As Object
Set db = CurrentDb()
Dim stLinkCriteria As String
stLinkCriteria = "[TripID]=" & Me![TripID]
RsSql = "SELECT * FROM [qCust] where " & stLinkCriteria & ";"
Set rs = db.OpenRecordset(RsSql, DB_OPEN_DYNASET)
Set xlApp = CreateObject("Excel.Application")
Set mysheet = xlApp.Workbooks.Open("D:\TMS\CustList.xlt").Sheets("Sheet1")
'-------------
j = 6
Do Until rs.EOF
mysheet.Cells(j, 1).Value = rs!Nums
mysheet.Cells(j, 2).Value = rs!CustLastFirstName
rs.MoveNext
j = j + 1
Loop
If mysheet.Cells(35, 2).Value = "" Then
mysheet.PageSetup.PrintArea = "A1:F34"
Else
mysheet.PageSetup.PrintArea = "A1:F63"
End If
'****** Get the filename ********
Dim strFileSpec As String
strFileSpec = "D:\TMS\CustList-" & Format([T_S_Date], "yymmdd") ".xls"
mysheet.Parent.SaveAs strFileSpec
xlApp.Visible = True
End Sub