กระทู้เก่าบอร์ด อ.Yeadram
1,166 2
URL.หัวข้อ /
URL
รบกวนดูโค้ด ในฟอร์มค้นในหน่อยครับ!
ตอนนี้มันค้นหาได้แค่ 2 ฟิลด์ คือ
cbAgriculturTypeSearch
cbPlantNameSearch
นอกนั้นไม่ได้เลยครับ
เช่น เลือกจังหวัด ทั้งที่มีข้อมูลจังหวัดนั้น แต่ผลคือ ว่างเปล่า ครับ
คอมโบอื่นๆ ก็เหมือนกันครับ นอกเหนือจาก 2 ตัวข้างบน
Private Sub cbAgriculturTypeSearch_Change()
cbPlantNameSearch.RowSource = "Select PlantId, PlantName From TB_Plant Where ([AgriculturTypeCode] Like '" & cbAgriculturTypeSearch & "')"
cbPlantNameSearch.Requery
If cbAgriculturTypeSearch <> "" Then filterMe
End Sub
Private Sub cbPlantNameSearch_Change()
If cbPlantNameSearch <> "" Then filterMe
End Sub
Private Sub cbProvinceSearch_Change()
On Error Resume Next
cbAmphurSearch.RowSource = "Select AmphurCode, Amphur From CodeAmphur Where ProvinceCode = " & cbProvinceSearch
cbAmphurSearch.Requery
cbTambonSearch.RowSource = "Select TambonCode, Tambon From CodeTambon Where ProvinceCode = " & cbProvinceSearch
cbTambonSearch.Requery
If cbProvinceSearch <> "" Then filterMe
End Sub
Private Sub cbAmphurSearch_Change()
On Error Resume Next
cbTambonSearch.RowSource = "Select TambonCode, Tambon From CodeTambon Where AmphurCode = " & cbAmphurSearch
cbTambonSearch.Requery
If cbAmphurSearch <> "" Then filterMe
End Sub
Private Sub cbTambonSearch_Change()
If cbTambonSearch <> "" Then filterMe
End Sub
Private Sub CmdPrintAgricultur_Click()
DoCmd.OpenReport "ReportAgricultur", acViewPreview, , , , Me.RecordSource
End Sub
Private Sub txtFirstDate_Change()
If txtFirstDate <> "" Then filterMe
End Sub
Private Sub txtLastDate_Change()
If txtLastDate <> "" Then filterMe
End Sub
Sub filterMe()
On Error Resume Next
Dim FAgricultur As String
Dim FPlantName As String
Dim FProvince As String
Dim FAmphur As String
Dim FTambon As String
Dim FFirstDate As String
Dim FLastDate As String
If cbAgriculturTypeSearch = "" Or IsNull(cbAgriculturTypeSearch) Or cbAgriculturTypeSearch = "*" Then FAgricultur = "*" _
Else: FAgricultur = cbAgriculturTypeSearch.Column(1)
If cbPlantNameSearch = "" Or IsNull(cbPlantNameSearch) Or cbPlantNameSearch = "*" Then FPlantName = "*" _
Else FPlantName = cbPlantNameSearch.Column(1)
If cbProvinceSearch = "" Or IsNull(cbProvinceSearch) Or cbProvinceSearch = "*" Then FProvince = "*" _
Else: FProvince = cbProvinceSearch.Column(1)
If cbAmphurSearch = "" Or IsNull(cbAmphurSearch) Or cbAmphurSearch = "*" Then FAmphur = "*" _
Else FAmphur = cbAmphurSearch.Column(1)
If cbTambonSearch = "" Or IsNull(cbTambonSearch) Or cbTambonSearch = "*" Then FTambon = "*" _
Else FTambon = cbTambonSearch.Column(1)
If txtFirstDate = "" Or IsNull(txtFirstDate) Or txtFirstDate = "*" Then FFirstDate = "*" _
Else FFirstDate = txtFirstDate
If txtLastDate = "" Or IsNull(txtLastDate) Or txtLastDate = "*" Then FLastDate = "*" _
Else FLastDate = txtLastDate
txtFarmerId = ""
Me.RecordSource = "SELECT * FROM SearchAgricultur WHERE AgriculturType like '" & FAgricultur & "' and PlantName like '" & FPlantName & "' and Province like '" & FProvince & "' and Amphur like '" & FAmphur & "' and Tambon like '" & FTambon & "' and HavestDate like '" & FFirstDate & "' and HavestDate like '" & FLastDate & "'"
Me.Requery
End Sub
cbAgriculturTypeSearch
cbPlantNameSearch
นอกนั้นไม่ได้เลยครับ
เช่น เลือกจังหวัด ทั้งที่มีข้อมูลจังหวัดนั้น แต่ผลคือ ว่างเปล่า ครับ
คอมโบอื่นๆ ก็เหมือนกันครับ นอกเหนือจาก 2 ตัวข้างบน
Private Sub cbAgriculturTypeSearch_Change()
cbPlantNameSearch.RowSource = "Select PlantId, PlantName From TB_Plant Where ([AgriculturTypeCode] Like '" & cbAgriculturTypeSearch & "')"
cbPlantNameSearch.Requery
If cbAgriculturTypeSearch <> "" Then filterMe
End Sub
Private Sub cbPlantNameSearch_Change()
If cbPlantNameSearch <> "" Then filterMe
End Sub
Private Sub cbProvinceSearch_Change()
On Error Resume Next
cbAmphurSearch.RowSource = "Select AmphurCode, Amphur From CodeAmphur Where ProvinceCode = " & cbProvinceSearch
cbAmphurSearch.Requery
cbTambonSearch.RowSource = "Select TambonCode, Tambon From CodeTambon Where ProvinceCode = " & cbProvinceSearch
cbTambonSearch.Requery
If cbProvinceSearch <> "" Then filterMe
End Sub
Private Sub cbAmphurSearch_Change()
On Error Resume Next
cbTambonSearch.RowSource = "Select TambonCode, Tambon From CodeTambon Where AmphurCode = " & cbAmphurSearch
cbTambonSearch.Requery
If cbAmphurSearch <> "" Then filterMe
End Sub
Private Sub cbTambonSearch_Change()
If cbTambonSearch <> "" Then filterMe
End Sub
Private Sub CmdPrintAgricultur_Click()
DoCmd.OpenReport "ReportAgricultur", acViewPreview, , , , Me.RecordSource
End Sub
Private Sub txtFirstDate_Change()
If txtFirstDate <> "" Then filterMe
End Sub
Private Sub txtLastDate_Change()
If txtLastDate <> "" Then filterMe
End Sub
Sub filterMe()
On Error Resume Next
Dim FAgricultur As String
Dim FPlantName As String
Dim FProvince As String
Dim FAmphur As String
Dim FTambon As String
Dim FFirstDate As String
Dim FLastDate As String
If cbAgriculturTypeSearch = "" Or IsNull(cbAgriculturTypeSearch) Or cbAgriculturTypeSearch = "*" Then FAgricultur = "*" _
Else: FAgricultur = cbAgriculturTypeSearch.Column(1)
If cbPlantNameSearch = "" Or IsNull(cbPlantNameSearch) Or cbPlantNameSearch = "*" Then FPlantName = "*" _
Else FPlantName = cbPlantNameSearch.Column(1)
If cbProvinceSearch = "" Or IsNull(cbProvinceSearch) Or cbProvinceSearch = "*" Then FProvince = "*" _
Else: FProvince = cbProvinceSearch.Column(1)
If cbAmphurSearch = "" Or IsNull(cbAmphurSearch) Or cbAmphurSearch = "*" Then FAmphur = "*" _
Else FAmphur = cbAmphurSearch.Column(1)
If cbTambonSearch = "" Or IsNull(cbTambonSearch) Or cbTambonSearch = "*" Then FTambon = "*" _
Else FTambon = cbTambonSearch.Column(1)
If txtFirstDate = "" Or IsNull(txtFirstDate) Or txtFirstDate = "*" Then FFirstDate = "*" _
Else FFirstDate = txtFirstDate
If txtLastDate = "" Or IsNull(txtLastDate) Or txtLastDate = "*" Then FLastDate = "*" _
Else FLastDate = txtLastDate
txtFarmerId = ""
Me.RecordSource = "SELECT * FROM SearchAgricultur WHERE AgriculturType like '" & FAgricultur & "' and PlantName like '" & FPlantName & "' and Province like '" & FProvince & "' and Amphur like '" & FAmphur & "' and Tambon like '" & FTambon & "' and HavestDate like '" & FFirstDate & "' and HavestDate like '" & FLastDate & "'"
Me.Requery
End Sub
2 Reply in this Topic. Dispaly 1 pages and you are on page number 1
2 @R13297
ตรง HavestDate ตอนนี้ ok แล้วครับตามที่ คุณ PichaiTc แนะนำครับ
Time: 0.3070s
ถ้าเป็น date ใช้ like ไม่ได้ครับ และตอนส่งค่า ให้คล่อมด้วย #...# เพื่อบอกให้ ระบบรู้ว่าเป็น date type ด้วยครับ