Like the first time through the Command1 selected 20 records, and then press Command2 setting-up a a.x ls of excel, and will be put into this article 20 record; But the next time through the Command1 10 records are selected, and then press Command2 setting-up a b.x ls of excel, the 10 deposit, found b.x ls before 10 records is the second choice, but there is 10, is a.x ls after 10, can do not cover, how do I write the code b.x ls only 10 records, each saved excel selected only a recent record, thank you
CodePudding user response:
Why don't you directly send code? Also get a picture, look very strange...That I not process variables? Command2 code?
CodePudding user response:
'Adodc1 connection table 1. XLS; Command1 according to conditions from 1. XLS selected recordPrivate Sub Command1_Click ()
"' the sentence for daily query '"'
Sqlstr1="select * from [sheet1 $] where year (time)='" & amp; Year & amp; "' and the month (time)='" & amp; The month & amp; "' and day (time)='" & amp; Day & amp; "'
"Adodc1. RecordSource=sqlstr1
Adodc1. Refresh
' ' ' ' 'the datagrid showed that the temperature of the query by the' "'
The Set DataGrid1. The DataSource=Adodc1
DataGrid1. Refresh
End Sub
'Command2 by path to create a new excle file, will be selected Command1 records stored in the file
Private Sub Command2_Click ()
Dim recordtime (300) As the String
Dim recordch1 (300) As Single
I=I + 1 'I was elected the record number of the Command1
Adodc1. You. MoveFirst
'take Command1 elected the first record
Recordtime (I)=Adodc1. You. Fields (" time ")
Recordch1 (I)=Adodc1. You. Fields (ch1 ")
'take record for the rest of the Command1 choose
While (Adodc1. You. AbsolutePosition & lt;> Adodc1. You. RecordCount)
Adodc1. You. MoveNext
I=I + 1
Recordtime (I)=Adodc1. You. Fields (" time ")
Recordch1 (I)=Adodc1. You. Fields (ch1 ")
DoEvents
Wend
Dim storeloca As String 'save the path
Set the Ex=CreateObject (" Excel. Application ")
The Set ExBook=Ex. Workbooks (). The Add
The Set ExSheet=ExBook. Worksheets (" Sheet1 ")
Storeloca=Trim (Trim (pos. Text) + Trim (", \ ") + Trim (nameexcel. Text) + Trim (". XLS "))
For j=1 To I
Cells (j, 1), (j)
Value=https://bbs.csdn.net/topics/recordtimeCells (j, 2), (j)
Value=https://bbs.csdn.net/topics/recordch1Next j
I=0
J=0
ActiveWorkbook. SaveAs (storeloca)
Ex. The Quit
The Set xlSheet=Nothing
The Set xlBook=Nothing
The Set XLS=Nothing
End Sub