17
ห้อง MS Access / : จะ Query จาก Colum ทำเป็น Row ได้อย่างไรครับ
« เมื่อ: 21 ก.พ. 62 , 21:43:37 »
ขอร่วมตอบครับอ.อ.ปิ่นณรงค์
โค๊ด: [Select]
Public Function MakeTableWithConvertToRow2(ByVal sMainTable As String, ByVal sTempTable As String)
'On Error Resume Next
Dim RS_IN As DAO.Recordset
Dim RS_OUT As DAO.Recordset
Dim ColName As Integer
Set RS_IN = CurrentDb.OpenRecordset("Select" & "* from " & sMainTable & "")
'Set RS_OUT = CurrentDb.OpenRecordset("Select" & "* from " & sTempTable & "")
Set RS_OUT = CurrentDb.OpenRecordset(sTempTable, dbOpenTable)
Do While Not RS_IN.EOF
RS_OUT.Index = "PrimaryKey"
RS_OUT.Seek "=", RS_IN(0).Value
For ColName = 0 To RS_OUT.Fields.Count - 1
If RS_OUT.NoMatch Then
RS_OUT.AddNew
Else
RS_OUT.Edit
End If
If RS_IN(1).Value = RS_OUT(ColName).Name Then
RS_OUT(0).Value = RS_IN(0).Value
RS_OUT(RS_OUT(ColName).Name).Value = RS_IN(2).Value
RS_OUT.Update
End If
Next
RS_IN.MoveNext
Loop
RS_IN.Close
RS_OUT.Close
Set RS_IN = Nothing
Set RS_OUT = Nothing
End Function
โพสต์นี้ได้รับคำขอบคุณจาก: ปิ่นณรงค์