Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Synchronizing a Form with Its Underlying Recordset


We use a form's RecordsetClone property to refer to its underlying recordset. You can manipulate this recordset independently of what's currently being displayed on the form. Here's an example:

Private Sub cboCompany_AfterUpdate()
'Use the recordset behind the form to locate the client
''selected in the combo box
Me.RecordsetClone.FindFirst "[ClientID] = " & cboCompany.Value
'If the client is not found, display a message
'Otherwise, synchronize the form with the underlying recordset
If Me.RecordsetClone.NoMatch Then
MsgBox "Client Not Found"
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

This example issues the FindFirst method on the form's RecordsetClone. It searches for a record in the form's underlying recordset whose ClientID is equal to the current combo box value. If a match is found, the form's bookmark is synchronized with the bookmark of the form's underlying recordset. You can rewrite this code, using an object variable to point at the RecordsetClone:

Private Sub cboCompany_AfterUpdate()
'Create a recordset based on the recordset underlying the form
Dim rst As Recordset
Set rst = Me.RecordsetClone
'Search for the client selected in the combo box
rst.FindFirst "ClientID = " & cboCompany.Value
'If the client is not found, display an error message
'If the client is found, move the bookmark of the form
'to the bookmark in the underlying recordset
If rst.NoMatch Then
MsgBox "Client Not Found"
Else
Me.Bookmark = rst.Bookmark
End If
End Sub

This code creates an object variable that points at the form's RecordsetClone. The recordset object variable can then be substituted for Me.RecordsetClone because it references the form's underlying recordset.

The RecordsetClone property allows you to navigate or operate on a form's records independently of the form. This is often useful when you want to manipulate the data behind the form without affecting the appearance of the form. On the other hand, when you use the Recordset property of the form, the act of changing which record is current in the recordset returned by the form's Recordset property also sets the current record of the form. Here's an example:

Private Sub cboSelectEmployee_AfterUpdate()
'Find the employee selected in the combo box
Me.Recordset.FindFirst "EmployeeID = " _
& Me.cboSelectEmployee
'If employee not found, display a message
If Me.Recordset.EOF Then
MsgBox "Employee Not Found"
End If
End Sub

Notice that it is not necessary to set the Bookmark property of the form equal to the Bookmark property of the recordset. They are one in the same.


/ 544