Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change a textbox value in a form with a checkbox click?

Status
Not open for further replies.

cadoltt

Programmer
Jun 9, 2005
85
CA
Hi everybody,

There is a textbox in my form (frm_01) for entering numeric values (%). I also want to put beside it a checkbox (chkb_not_reported) which if checked, changes the textbox value (and corresponding table field) into -99.

The textbox is bound to a table field, the checkbox is unbound (not sure if this is correct). I tried a few checkbox events to force the value to change, e.g.:

Code:
Private Sub chkb_not_reported_AfterUpdate()
  
  If chkb_not_reported.Value = 1 Then
    txb_percent.Text = "-99"
    txb_percent.Value = -99
  End If
  
  Form_frm_01.Repaint
  
End Sub

But none of them worked (other events I tried: Enter, Click, Exit).


Could anyone help me with this?


Thanks,

Alex
 
Unbind your text box and populate it in your code, wrapped in an If statement.

If chkb_not_reported.Value = 1 Then
txb_percent.Text = "-99"
Else
txb_percent = yourTableValue
End If

If the source of data for the form is a table or query and when you are on the form there is a current record populating the form, then you should be able to refer to the field name when populating that text box.

If not, you might wnt to create a recordset or use a DLookup function to pull in that value.
 
lynchg,

Thanks for your response.

The thing is that the main purpose of the form is to enter data into the table. I see from your post how to pull a value from a field (if the textbox is unbound) but it's still unclear to me how to enter a value into the field from an unbound texbox.

And another question is what event to use, AfterUpdate or something else.

Could you help me with this?


Thanks again,

Alex
 
Leave the texbox bound and instead of

Code:
If chkb_not_reported.Value = 1 Then

use either

Code:
If chkb_not_reported.Value = -1 Then
[code]

or better still

[code]
If chkb_not_reported Then
[code]

in the AfterUpdate event of the checkbox.


Have fun! :o)

Alex Middleton
 
Alex,

It works now.

Thanks a lot!

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top