ACC: Yes/No Field Not Evaluating "-1" or "0" in ComparisonsID: Q142229
|
Moderate: Requires basic macro, coding, and interoperability skills.
Code written in Access Basic that uses -1 or 0
to compare a Yes/No field in a table or recordset does not work
properly when you convert the Access Basic code to Visual Basic for
Applications code. In Microsoft Access version 2.0, which uses Access
Basic, the numeric comparisons are evaluated as strings. In Microsoft
Access 7.0 and 97, which uses Visual Basic for Applications, the numeric
comparisons are evaluated as Boolean values.
In Access Basic the condition
If rs![yesnofield] = "-1" Then
If rs![yesnofield] = "0" Then
In an open Access Basic or Visual Basic for Application Module window, use
the Find command on the Edit menu (or press CTRL+F) to check for instances
of the strings -1 or 0.
Change all instances in Visual Basic for Applications where "-1" or "0" is
used to compare a Yes/No field in a table or recordset as follows.
If you are using the following expression in Access Basic
IF rs![yesnofield] = "-1" Then
IF rs![yesnofield] = -1 Then
-or-
IF rs![yesnofield] = True Then
IF rs![yesnofield] = "0" Then
IF rs![yesnofield] = 0 Then
-or-
IF rs![yesnofield] = False Then
This behavior is by design.
Sub Form_Current()
Dim rs As Recordset
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark
If rs![Discontinued] = "-1" Then
MsgBox "This product is discontinued."
End If
Set rs = Nothing
End Sub
Sub Form_Current()
to read as follows:
Private Sub Form_Current()
For more information about the Boolean data type, search the Help Index for "Boolean data type," or ask the Microsoft Access 97 Office Assistant
Keywords : kbusage
Version : 7.0 97
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 29, 1999