Text box value based on a check box

J

jamccarley

I am new to writing code and have a question. My main form has a check box,
that when checked I would like a text box to show the words "ITR Issued". The
way I have it written works, but only on the record that you are on. if you
move to the next record it stays the value of whatever you last checked. Is
there something that I need to add to tie it to each record? Here is the code
I have so far.

Public Sub ITR_Needed_AfterUpdate()
If ITR_Needed.Value = -1 Then
Text565.Value = "ITR ISSUED"
Else
Text565.ForeColor = vbRed
Text565.Value = ""
End If

End Sub

Thank you
Josh
 
W

Wayne-I-M

Hi

It sounds to me as if you have an unbound tickbox on your form. The problem
with this is that your application will not know which record the "tick" is
applicable to.

Add a field to the table the form is based on and thyen use this to store
the "ticks" for that record.

Your code should then work.

Oh -
Text565.ForeColor = vbRed
Text565.Value = ""
You are allocating a forecolour to a space (which can't have a colour ?) -
this "may" be usful if you are going to type text inthe box - if not, it's
not needed and either way you don't Text565.Value = "". Plus you need to
change the colour back or the red will stay even if you do put a tick in
later (see code below)

Top - Tip - give each control on a form a name that means something to you -
not Text565 (unless this really means something)

Private Sub YourCheckBox_AfterUpdate()
If Me.YourCheckBox = -1 Then
Me.YourTextControl = "ITR Issued"
Me.YourTextControl.ForeColor = vbBlack
Else
Me.YourTextControl.ForeColor = vbRed
End If
End Sub
 
J

jamccarley

It is a bound tickbox. There is a "ITR Needed" field and the ticks are stored
correctly. I just can't get this one code to work.
 
W

Wayne-I-M

Use this

Private Sub ITR_Needed_AfterUpdate()
If Me.ITR_Needed = -1 Then
Me.Text565 = "ITR Issued"
Me.Text565.ForeColor = vbBlack
Else
Me.Text565.ForeColor = vbRed
Me.Text565.Value = ""
End Sub
 
M

Mujji

I guess you are using VB6.0 to develop this.

Whats this ITR_Needed? Is this a control or a recordset?


Thx,
Mujeeb.
 
K

Ken Sheridan

Josh:

Setting the properties of an unbound control in another control's
AfterUpdate event procedure will effect all instances of that control until
the properties are specifically changed again, i.e. when the AfterUpdate
event procedure next executes. could call the code from a variety of
different event procedures to cover all bases, but far easier is to use a
combination of conditional formatting, along with the ControlSource property
of the Text565 control to pull in the value:

1. For the conditional formatting use the expression:

Not [ITR_Needed.Value]

to set the ForeColor to red.

2. For the ControlSource property of the Text565 control use:

=IIf("[ITR_Needed.Value]", "ITR ISSUED","")

BTW referring to the value of a Boolean (Yes/No) column as -1 is what the
head of a software company of my acquaintance once termed "being unduly
chummy with the implementation". Reliance on the implementation is not good
programming practice. Use the Boolean constants of TRUE or FALSE rather than
their implementation as -1 or 0. In the above you'll see that I have not
actually used either; this is because simply referencing a Boolean column or
control by name returns its value, the Value property being the default.
Similarly you can omit '.Value' when assigning a value to a control. One
exception to this that I know of (which can be regarded as bug and may for
all I know have been cured in later versions of Access) was when changing the
printer currently used by Access, where the following, which sets the printer
to one selected in a list box, works:

Set Application.Printer = Application.Printers.Item(Me!lstPrinters.Value)

but this doesn't:

Set Application.Printer = Application.Printers.Item(Me!lstPrinters)

Ken Sheridan
Stafford, England
 

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

Top