สอบถามเรื่องการ loop ให้แสดง หลาย บรรทัดยังไงครับ ตอนนี้แสดงเพียงแค่ บรรทัดเดียว ทั้งๆที่มีหลายรายการ ในช่อง
goodcode GoodName1 DocuNo BrchID ตอนนี้จะแสดงเพียง แค่บรรทัดเดียว
Sub setpriceducudate()
Dim x As Long, y As Long, RowInt As Long
Dim SQL As String
Dim goodcode As Variant
Dim BeginDate As Variant
Dim GoodName1 As Variant
Dim DocuNo As Variant
Dim rs As New ADODB.Recordset
Call ConficCon
x = Selection.Rows(1).Row
y = Selection.Rows.Count + x - 1
For RowInt = x To y
BeginDate = Cells(RowInt, 1)
goodcode = Cells(RowInt, 2)
GoodName1 = Cells(RowInt, 3)
DocuNo = Cells(RowInt, 4)
BrchID = Cells(RowInt, 5)
SQL = " SELECT EMSetPriceHD.BeginDate, EMGood.GoodCode, EMGood.GoodName1, EMSetPriceHD.DocuNo, EMSetPriceHD.BrchID"
SQL = SQL & " FROM (EMGood INNER JOIN EMSetPriceDT ON EMGood.GoodID = EMSetPriceDT.ListID) INNER JOIN EMSetPriceHD ON EMSetPriceDT.SetPriceID = EMSetPriceHD.SetPriceID"
SQL = SQL & " WHERE (((EMSetPriceHD.BeginDate)= '" & BeginDate & "'));"
rs.Open SQL, Connection_String
Cells(RowInt, 2) = rs.Fields("goodcode")
Cells(RowInt, 3) = rs.Fields("GoodName1")
Cells(RowInt, 4) = rs.Fields("DocuNo")
Cells(RowInt, 5) = rs.Fields("BrchID")
rs.Close
Next RowInt
End Sub
สอบถามเรื่องการ loop ให้แสดงผลในบรรทัดถัดไป VBA
goodcode GoodName1 DocuNo BrchID ตอนนี้จะแสดงเพียง แค่บรรทัดเดียว
Sub setpriceducudate()
Dim x As Long, y As Long, RowInt As Long
Dim SQL As String
Dim goodcode As Variant
Dim BeginDate As Variant
Dim GoodName1 As Variant
Dim DocuNo As Variant
Dim rs As New ADODB.Recordset
Call ConficCon
x = Selection.Rows(1).Row
y = Selection.Rows.Count + x - 1
For RowInt = x To y
BeginDate = Cells(RowInt, 1)
goodcode = Cells(RowInt, 2)
GoodName1 = Cells(RowInt, 3)
DocuNo = Cells(RowInt, 4)
BrchID = Cells(RowInt, 5)
SQL = " SELECT EMSetPriceHD.BeginDate, EMGood.GoodCode, EMGood.GoodName1, EMSetPriceHD.DocuNo, EMSetPriceHD.BrchID"
SQL = SQL & " FROM (EMGood INNER JOIN EMSetPriceDT ON EMGood.GoodID = EMSetPriceDT.ListID) INNER JOIN EMSetPriceHD ON EMSetPriceDT.SetPriceID = EMSetPriceHD.SetPriceID"
SQL = SQL & " WHERE (((EMSetPriceHD.BeginDate)= '" & BeginDate & "'));"
rs.Open SQL, Connection_String
Cells(RowInt, 2) = rs.Fields("goodcode")
Cells(RowInt, 3) = rs.Fields("GoodName1")
Cells(RowInt, 4) = rs.Fields("DocuNo")
Cells(RowInt, 5) = rs.Fields("BrchID")
rs.Close
Next RowInt
End Sub