Uygulama Çalışırken Formun Kayıt Kaynağını Değiştirmek - Kod Detayı
Private Sub cmdShowSales_Click()
‘Ending Date değeri Beginning Date değerinden sonra gelmelidir.
If Me.txtEndingDate < Me.txtBeginningDate Then
MsgBox "Bitiş tarihi değeri başlangıç tarihinden sonra gelmelidir"
txtBeginningDate.SetFocus
Exit Sub
End If
‘Kullanıcı tarafından girilen arama kriterlerini kullanarak bir SQL ifadesi yarat ve
‘ShowSalesSubform’un RecordSource özelliğini ayarla.
Dim strSQL As String
Dim strRestrict As String
Dim lngX As Long
lngX = Me.optSales.Value
strRestrict = ShowSalesValue(lngX)
‘Create SELECT ifade.
strSQL = “SELECT DISTINCTROW tblCustomers.CompanyName,_
qryOrderSubtotals.OrderID, “
strSQL = strSQL & “qryOrderSubtotals.Subtotal “ & _
“tblOrders.ShippedDate “
strSQL = strSQL & “FROM tblCustomers INNER JOIN _
(qryOrderSubtotals INNER JOIN tblOrders ON “
strSQL = strSQL & “qryOrderSubtotals.OrderID = “ & _
“tblOrders.OrderID) ON “
strSQL = strSQL & “tblCustomers.CustomerID = tblOrders.CustomerID “
strSQL = strSQL & “WHERE (tblOrders.ShippedDate _
Between Forms!frmShowSales!txtBeginningDate “
strSQL = strSQL & “And Forms!frmShowSales!txtEndingDate) “
strSQL = strSQL & “And “ & strRestrict
strSQL = strSQL & “ ORDER BY qryOrderSubtotals.Subtotal DESC;”
‘ShowSalesSubform’un Record Source özelliğini ayarla.
Me.fSubShowSales.Form.RecordSource = strSQL
‘Kriterlere uyan hiç kayıt yoksa, alt formun Record Source özelliğini tekrar ayarla,
‘bir mesaj görüntüle ve odağı BeginningDate metin kutusuna aktar.
If Me.fSubShowSales.Form.RecordsetClone.RecordCount = 0 Then
Me.fSubShowSales.Form.RecordSource = _
“SELECT CompanyName FROM tblCustomers WHERE False;”
MsgBox “Girdiğiniz kriterlere uyan bir kayıt bulunamadı”, _
vbExclamation, “Kayıt Bulunamadı”
Me.txtBeginningDate.SetFocus
Else ‘Detail bölümündeki denetimi aktifleştir.
EnableControls Me, acDetail, True
‘Ekleme noktasını ShowSalesSubform’a aktar.
Me.fSubShowSales!txtCompanyName.SetFocus
End If
End Sub
Private Function ShowSalesValue(lngOptionGroupValue As Long) As String
‘Sales seçenek grubu seçili değeri gönder. Seçenek grubu değerleri için sabitler tanımla.
Const conSalesUnder1000 = 1
Const conSalesOver1000 = 2
Const conAllSales = 3
‘seçenek grubu değerine dayanan bir koşul yarat.
Select Case lngOptionGroupValue
Case conSalesUnder1000:
ShowSalesValue = “qryOrderSubtotals.Subtotal < 1000”
Case conSalesOver1000:
ShowSalesValue = “qryOrderSubtotals.Subtotal >= 1000”
Case Else
ShowSalesValue = “qryOrderSubtotals.Subtotal = True”
End Select
End Function