เรียนถามอ. BADMan และเพื่อนๆทุกท่าน
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 217   1
URL.หัวข้อ / URL
เรียนถามอ. BADMan และเพื่อนๆทุกท่าน

ผมได้นำตัวอย่างของอ.ไปใช้งาน แล้วติดปัญหาเรื่องความหมายของ Code คือมีError เกิดขึ้นกับการนำไปใช้ ตอนนี้ผมแก้ได้แล้วเป็นแบบเดาเอานะครับ อ.ช่วยแปลให้ผมหน่อยนะครับ ขอบคุณครับ
Sub CreateReportQuery()
On Error GoTo Err_CreateQuery

Dim db As Database
Dim rs As Recordset
Dim qdf As QueryDef
Dim fld As Field
Dim indexx As Integer ' ตั้งตัวแปรสำหรับ Control Source ของ Field Index แรกจนถึง Field Index สุดท้าย
Dim FieldList As String ' ตั้งตัวแปรสำหรับ Control Source ของชื่อ Field ตั้งแต่ Field แรกจนถึง Field สุดท้าย
Dim strSQL As String
Dim i As Integer

Set db = CurrentDb
Set qdf = db.QueryDefs("qryCostTapVacuum")
indexx = 0
For Each fld In qdf.Fields
If fld.Type >= 0 And fld.Type <= 12 Or fld.Type = 12 Then
FieldList = FieldList & "[" & fld.NAME & "] as Field" & indexx & ", "
' ReportLabel(indexx) = fld.NAME

Select Case fld.NAME
Case 1
ReportLabel(indexx) = "มค"
Case 2
ReportLabel(indexx) = "กพ"
Case 3
ReportLabel(indexx) = "มีค"
Case 4
ReportLabel(indexx) = "เมย"
Case 5
ReportLabel(indexx) = "พค"
Case 6
ReportLabel(indexx) = "มิย"
Case 7
ReportLabel(indexx) = "กค"
Case 8
ReportLabel(indexx) = "สค"
Case 9
ReportLabel(indexx) = "กย"
Case 10
ReportLabel(indexx) = "ตค"
Case 11
ReportLabel(indexx) = "พย"
Case 12
ReportLabel(indexx) = "ธค"
End Select
End If
indexx = indexx + 1
Next fld
.......................>ผมอยากจะทรายความหมายตั้งแต่ตรงนี้บรรทัดนี้นะครับว่าแปลว่าอะไร ผมได้เปลี่ยนจาก FieldList = Left(FieldList, Len(FieldList) - 2) เป็น FieldList = Left(FieldList, Len(FieldList) - 1)

For i = indexx To 12
FieldList = FieldList & "null as Field" & i & ","
Next i

FieldList = Left(FieldList, Len(FieldList) - 1)

strSQL = "Select " & FieldList & " From qryCostTapVacuum;"

db.QueryDefs.Delete "qryvacCrosstap"
Set qdf = db.CreateQueryDef("qryvacCrosstap", strSQL)


Exit_CreateQuery:
Exit Sub

Err_CreateQuery:
If Err.Number = 3265 Then '*** if the error is the query is missing
Resume Next '*** then skip the delete line and resume on the next line
Else
MsgBox Err.Description '*** write out the error and exit the sub
Resume Exit_CreateQuery
End If
End Sub

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

1 @R06777
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0522s