ACC95: Using FindFirst Method to Find a GUID Generates an Error (155194)
The information in this article applies to:
- Microsoft Access for Windows 95 7.0
This article was previously published under Q155194
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you use the FindFirst method of a recordset to find a globally unique
identifier (GUID), you may receive one of the following error messages:
Malformed GUID in expression
-or-
GUID not allowed in Find method criteria expression
If you use the Combo Box Wizard on a form to create a combo box that finds
a record based on a replication ID value, you may also receive this error.
This is because the wizard generates Visual Basic for Applications code
that uses the FindFirst method.
CAUSE
A GUID is a 16-byte array. In table Datasheet view, a GUID appears as a
string of hexadecimal numbers enclosed in braces. The value of an
unbound combo box whose bound column is a GUID will be a string of
hexadecimal numbers enclosed by braces. The FindFirst method will not be
able to find a record with a GUID equal to that string.
RESOLUTION
Create an AfterUpdate event procedure that moves through the form's
recordsetclone to find the record with the GUID that matches the value in
the combo box. Set the bookmark of the form to the bookmark of the
recordsetclone.
The following example shows you how to find a record on a form using a
combo box whose bound column is a GUID:
- Open the sample database Northwind.mdb.
- Copy the Employees table and paste it as Employees1.
- Open the Employees1 table in Design view.
- Change the EmployeeID Field Size property to Replication ID and save the
table.
- Create a new form based on the Employees1 table using the AutoForm:
Columnar wizard. Save the form as Employees1.
- Open the Employees1 form in Design view.
- Create an unbound combo box on the form with the following properties:
Combo box: GUIDFind
---------------------
Name: GUIDFind
RowSource: Employees1
ColumnCount: 2
ColumnWidths: 0";1"
- Set the AfterUpdate property of the combo box to the following event
procedure:
Private Sub GUIDFind_AfterUpdate()
Dim rs as Recordset
Dim findguid as String
findguid = "{guid " & Me!GUIDFind & "}"
Set rs = Me.RecordsetClone
rs.MoveFirst
Do Until rs.EOF
If rs!EmployeeID = findguid Then
Me.Bookmark = rs.Bookmark
Exit Sub
End If
rs.MoveNext
Loop
End Sub
- Open the form in Form view. Select a value from the combo box and
notice that the form displays the correct record.
REFERENCES
For more information about globally unique identifiers, search for "GUIDs,"
using the Microsoft Access 7.0 Help Index.
For more information about the StringFromGUID function, see the section
called "Referring to a Replication ID Field in Code" in the Acreadme.txt
file, which is located in the Microsoft Access 7.0 program folder.
Modification Type: | Major | Last Reviewed: | 7/2/2002 |
---|
Keywords: | kbprb kbusage KB155194 |
---|
|