VBA coding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a form I have a yes/no field called NEW. When it is Yes I want to place a
X in the text field LabelFlag. Both fields are in the data base table.
The expression: If [NEW] is Yes or "Yes" Then [LabelFag] is "X" will not
compile.
 
Bob,

Do you have yes/no field as a checkbox? If so, then it would return either
a -1 for a checked field and a 0 as an unchecked field.

So here's how I would do it (assuming you have a checkbox titled "New"). On
the AfterUpdate event for the checkbox:

If NEW = -1 Then
Me!LabelFlag = "X"
Elseif NEW = 0 Then
Me!LabalFlag = Null
End If

You would also need to put this same code on the OnLoad or OnOpen for the
base form to ensure that defaults are overridden.

HTH

Aaron G
Philadelphia, PA
 
a Yes/No field in a table is actually a Boolean data type (True/False
or -1/0). in the form's module, try

If Me!NEW Then Me!LabelFlag = "X"

if you want the opposite to also occur - if New=False then remove "X" from
LabelFlag, try this instead, as

If Me!NEW Then
Me!LabelFlag = "X"
Else
Me!LabelFlag = Null
End If

btw, if the New field in the table is a Text data type, rather than Yes/No,
then ignore the above and try this code, as

If Me!NEW = "Yes" Then Me!LabelFlag = "X"

hth
 
Bob,

I just noticed you said the LabelFlag was a bound field. In that case you
do NOT need to add the code the the OnLoad or OnOpen property - you would
only need to do so if the field was unbound. Sorry for the confusion
again... i just finished doing a similar function for an unbound field so it
was in my head.

Aaron G
Philadelphia, PA
 
In the After Update of the NEW checkbox enter the following:

Private Sub New_AfterUpdate()

If [New] = True Then
LabelFlag = "X"
Else
LabelFlag = ""
End If

End Sub

However, I strongly recommend changing the name of the checkbox b/c is a
reserved word in VBA
 
Bob,

Sorry... I left out the "Me!" in front of the "NEW" in that code!

So your code should look like:

If Me!NEW = -1 Then
Me!LabelFlag = "X"
Elseif Me!NEW = 0 Then
Me!LabalFlag = Null
End If

Sorry about that!

Aaron G
Philadelphia, PA
 
This does not seem to work. The field I'm really updating with X is text
field with out formating or input mask called 2ND OTHER ADULT SS#. My routine
looks like:

Private Sub NEW_AfterUpdate()
If [NEW] = True Then
[2ND OTHER ADULT SS#] = "X"
Else
[2ND OTHER ADULT SS#] = ""
End If
End Sub


xRoachx said:
In the After Update of the NEW checkbox enter the following:

Private Sub New_AfterUpdate()

If [New] = True Then
LabelFlag = "X"
Else
LabelFlag = ""
End If

End Sub

However, I strongly recommend changing the name of the checkbox b/c is a
reserved word in VBA

Bob B said:
In a form I have a yes/no field called NEW. When it is Yes I want to place a
X in the text field LabelFlag. Both fields are in the data base table.
The expression: If [NEW] is Yes or "Yes" Then [LabelFag] is "X" will not
compile.
 
Your coding did the trick. It seems like xRoachx's should also have worked

tina said:
a Yes/No field in a table is actually a Boolean data type (True/False
or -1/0). in the form's module, try

If Me!NEW Then Me!LabelFlag = "X"

if you want the opposite to also occur - if New=False then remove "X" from
LabelFlag, try this instead, as

If Me!NEW Then
Me!LabelFlag = "X"
Else
Me!LabelFlag = Null
End If

btw, if the New field in the table is a Text data type, rather than Yes/No,
then ignore the above and try this code, as

If Me!NEW = "Yes" Then Me!LabelFlag = "X"

hth


Bob B said:
In a form I have a yes/no field called NEW. When it is Yes I want to place a
X in the text field LabelFlag. Both fields are in the data base table.
The expression: If [NEW] is Yes or "Yes" Then [LabelFag] is "X" will not
compile.
 
Bob, I'm not sure why my code didn't work b/c I tested it before I posted it...

But at least you got it working as you wanted. :-)

Bob B said:
Your coding did the trick. It seems like xRoachx's should also have worked

tina said:
a Yes/No field in a table is actually a Boolean data type (True/False
or -1/0). in the form's module, try

If Me!NEW Then Me!LabelFlag = "X"

if you want the opposite to also occur - if New=False then remove "X" from
LabelFlag, try this instead, as

If Me!NEW Then
Me!LabelFlag = "X"
Else
Me!LabelFlag = Null
End If

btw, if the New field in the table is a Text data type, rather than Yes/No,
then ignore the above and try this code, as

If Me!NEW = "Yes" Then Me!LabelFlag = "X"

hth


Bob B said:
In a form I have a yes/no field called NEW. When it is Yes I want to place a
X in the text field LabelFlag. Both fields are in the data base table.
The expression: If [NEW] is Yes or "Yes" Then [LabelFag] is "X" will not
compile.
 
well, i gave you more than one coding suggestion and you didn't mention
which one worked for your needs, so i can't guess why xRoachx's code didn't
work for you. but at any rate your problem is solved, so that's good. :)


Bob B said:
Your coding did the trick. It seems like xRoachx's should also have worked

tina said:
a Yes/No field in a table is actually a Boolean data type (True/False
or -1/0). in the form's module, try

If Me!NEW Then Me!LabelFlag = "X"

if you want the opposite to also occur - if New=False then remove "X" from
LabelFlag, try this instead, as

If Me!NEW Then
Me!LabelFlag = "X"
Else
Me!LabelFlag = Null
End If

btw, if the New field in the table is a Text data type, rather than Yes/No,
then ignore the above and try this code, as

If Me!NEW = "Yes" Then Me!LabelFlag = "X"

hth


Bob B said:
In a form I have a yes/no field called NEW. When it is Yes I want to place a
X in the text field LabelFlag. Both fields are in the data base table.
The expression: If [NEW] is Yes or "Yes" Then [LabelFag] is "X" will not
compile.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top