Halo Mas Mac, untuk membuat kriteria dengan operator lain secara bebas, maka query harus dibuat via VBA, tidak melalui design view ataupun SQL view. Sebagai contoh:
Private Sub Command1_Click()
On Error GoTo msgerr
Dim db As DAO.Database
Dim qrydef As DAO.QueryDef
Dim strSQL As String
strSQL = "SELECT NamaTable.NamaField1, NamaTable.NamaField2 " & _
"FROM NamaTable " & _
"WHERE NamaTable.Field1>=" & Me![NamaVariable1] & ";"
DoCmd.DeleteObject acQuery, "NamaQuery"
Set db = CurrentDb()
Set qrydef = db.CreateQueryDef("NamaQuery", strSQL)
Application.RefreshDatabaseWindow
qrydef.Close
db.Close
Set qrydef = Nothing
Set db = Nothing
Exit Sub
msgerr:
If Err.Number = 7874 Then
Resume Next
Else
MsgBox Err.Number & ". " & Err.Description, vbCritical, Err.Source
End If
End Sub
On Error GoTo msgerr
Dim db As DAO.Database
Dim qrydef As DAO.QueryDef
Dim strSQL As String
strSQL = "SELECT NamaTable.NamaField1, NamaTable.NamaField2 " & _
"FROM NamaTable " & _
"WHERE NamaTable.Field1>=" & Me![NamaVariable1] & ";"
DoCmd.DeleteObject acQuery, "NamaQuery"
Set db = CurrentDb()
Set qrydef = db.CreateQueryDef("NamaQuery", strSQL)
Application.RefreshDatabaseWindow
qrydef.Close
db.Close
Set qrydef = Nothing
Set db = Nothing
Exit Sub
msgerr:
If Err.Number = 7874 Then
Resume Next
Else
MsgBox Err.Number & ". " & Err.Description, vbCritical, Err.Source
End If
End Sub
Prosedure diatas akan membuat query baru dengan kriterianya secara langsung dan bebas, bukan lagi merujuk ke NamaVariable1, tapi langsung isi dari field text box dari NamaVariable1 itu sendiri.
Wassalaamu'alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi
Access Course by Request: http://wp.me/PW3LC-hR
Sofyan Efendi
Access Course by Request: http://wp.me/PW3LC-hR
----- Original Message -----From: mac baSent: Friday, December 21, 2012 10:30 AMSubject: [belajar-access] Merubah criteria pada query dengan coding VBA
__._,_.___
Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (26) |
SPAM IS PROHIBITED
.
__,_._,___
Tidak ada komentar:
Posting Komentar