Mismatch between Yes/No and Boolean (1 Viewer)

ListO

Señor Member
Local time
Today, 14:21
Joined
Feb 2, 2000
Messages
162
On a form called "MainLarge" I have a field from my table called "Tag," which is Boolean.

I want a public subroutine to process the state of that field with the following code (truncated here for simplicity). The MainLarge form is open when the subroutine is called.
Code:
Sub ToggleTag()
Dim TagState As Boolean
 
       TagState = [Forms]![MainLarge].[Tag]

   
   'Process the value of TagState 

      'Then save it back to the form, and thus, the table
      [Forms]![Mainlarge].[Tag] = Tagstate

End Sub
This fails with a Run-Time Error 13 - Type Mismatch.

I'm doing something wrong. What is the correct way to work with booleans in this situation?

Previously I had this code attached to the form itself and it worked fine.
 
Last edited:

MarkK

bit cruncher
Local time
Today, 06:21
Joined
Mar 17, 2004
Messages
8,186
An Access.Form has a built-in property called Tag, and it's a string. Since you don't know about it, it's almost certainly not set, so your error occurs because your code is trying to assign the empty string "" to the boolean, TagState.

One work around is address the forms controls collection directly, using . . .
Code:
TagState = Forms!MailLarge.Controls("Tag")
. . . which will distinguish your field from the built-in property.
 

ListO

Señor Member
Local time
Today, 14:21
Joined
Feb 2, 2000
Messages
162
Success! Thank you, thank you, thank you. I couldn't find anything in my books that would lead me to this solution.

I've very glad that I didn't simplify my example by changing variable names.

I appreciate your detailed attentions.

-Curt
 

Users who are viewing this thread

Top Bottom