ACC2002: No Records Are Displayed in a Subform That Is Based on a SQL Server Table (295219)
The information in this article applies to:
This article was previously published under Q295219 Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies only to a Microsoft Access database (.mdb).
SYMPTOMS
When you open a form that contains a subform that is based on a linked Microsoft SQL Server table, the subform does not display any records.
CAUSE
The fields that are used to link the subform to the main form are using the SQL Server UniqueIdentifier data type.
RESOLUTION
You can work around this problem by using a custom Visual Basic for Applications procedure that uses the StringFromGUID method on the Current event of the form. The following example demonstrates how to use this procedure. Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. - First, follow the steps in the "Steps to Reproduce the Behavior" section later in this article to reproduce the problem.
- Then, open the frmMyCategories form in Design view.
- Click the subform object, and then on the View menu, click Properties.
- On the Data tab of the property sheet, clear the LinkChildFields and LinkMasterFields properties.
- On the View menu, click Code to view the module of the form.
- Add the following code to the Current event procedure of the form:
Private Sub Form_Current()
Dim strSQL As String
If Not Me.NewRecord Then
strSQL = "SELECT * FROM dbo_MyProducts WHERE " & _
"dbo_MyProducts.fCategoryID = " & _
StringFromGUID(Me.Controls("CategoryID").Value)
Else
strSQL = "SELECT * FROM dbo_MyProducts WHERE False"
End If
Me.Controls("dbo_MyProducts").Form.RecordSource = strSQL
End Sub
- On the File menu, click Close and Return to Microsoft Access.
- Save the frmMyCategories form, and then close it.
- Open the frmMyProducts form in Design view.
- On the View menu, click Code to view the module of the form.
- Add the following code to the BeforeInsert event procedure of the form:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Controls("fCategoryID").Value = _
Me.Parent.Controls("CategoryID").Value
End Sub
- On the File menu, click Close and Return to Microsoft Access.
- Save the frmMyProducts form, and then close it.
- Open the frmMyCategories form in Form view.
- Enter a new category name in the main form, and then add several new products in the subform.
- Close and then reopen the form.
Note that Microsoft Access correctly displays the related records in the subform based on the current record in the main form.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCESFor more information about the StringFromGUID method, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type StringFromGUID method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kbbug kbdta kbnofix KB295219 |
---|
|