Export Data to excel โดยมีเงื่อนไข
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 287   3
URL.หัวข้อ / URL
Export Data to excel โดยมีเงื่อนไข

จาก code ข้างล่างนี้ ต้องการที่จะ export data ไปที่ excel โดยมีเงื่อไข ค่ะ แต่ข้อมูลกลับได้ทั้งหมดเลย ตามที่ ชื่อ query สร้างไว้
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7 ,qryaction, "d:\Outstanding.xls"
เราควรจะแก้ไขได้อย่างไรบ้างค่ะ ขอบคุณมากค่ะ
Private Sub cmdExport_Click()
Dim strWhere As String
If Me.cboLots <> "" Then
strWhere = "LotsResponse='" & Me.cboLots & "' "
End If
If Me.cboAction <> "" Then
If strWhere <> "" Then
strWhere = strWhere & "AND Action='" & Me.cboAction & "' "
Else
strWhere = "action='" & Me.cboAction & "' "
End If
End If

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7 ,qryaction, "d:\Outstanding.xls"
End Sub

3 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R05123
ผมว่า ลองวิธีง่ายๆก่อน ดีมั๊ยครับ
โดย query นั้น กำหนดเป็น Make-Table Query (โดยมีเงื่อนไขที่ต้องการ)
จากนั้น สร้าง Command button ให้ RUN query ก่อน
...
และสร้าง command button อีกอันหนึ่ง ให้ export (destination) Table
ที่ Make-Table ขึ้นมานั้น ไปยัง Excel
2 @R05124
คำสั่ง สำหรับ Export (destination) Table (ชื่อ table ตามคำสั่งข้างล่างนี้ ชื่อ exportExcel )ไปยัง Excel ครับ พร้อมกับ เปิด file excel นั้นๆ ด้วย

----->
Function run()
On Error GoTo run_Err

DoCmd.TransferSpreadsheet acExport, 8, "exportExcel", "c:\temp.xls", False, ""
Call Shell("""C:\Program Files\Microsoft Office\Office\Excel.exe"" \temp.xls", 1)


run_Exit:
Exit Function

run_Err:
MsgBox Error$
Resume run_Exit

End Function
3 @R05134
ผมคิดว่าคุณไม่ได้กำหนดเงื่อนไขนะครับ เพราะเห็นใช้ qryaction
ไม่รู้ว่าใน qryaction กำหนดเงื่อนไขไว้หรือป่าวครับ?
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0752s