Coding Help!!

mapat

Registered User.
Local time
Yesterday, 18:25
Joined
Feb 2, 2007
Messages
176
Hello,

On a form:
I have a text box "txtA".
I have a combo box that displays "A" or "B" or "C" to select.

When "A" is selected in the combo box, then I have to display double the value of "txtA" in any result text box (txt_result).

I wanna do this using code (with an "if then" statement) , but don't know how to or where to do this.

What I'm trying to do would look something like this:
if combobox="A" then
txt_result = txtA * 2 // is this right???
End If

Thank you very much in advance
 
try..
if Me.combobox = "A" then
Me.txt_result = Me.txtA * 2
...


and you might consider a 'select case' statement rather than 'if then'...it's a bit more elegant IMO

Select Case Me.combobox
Case "A"
Me.txt_result = Me.txtA * 2
Case "B"
'whatever you want to do if B is selected
Case "C"
'whatever you want to do if C is selected
Case Else
'whatever you want to do if anything other than A, B, or C is selected
End Select
 
I inserted your code, but still the same - please check!!

I put this code in the AfterUpdate part of the "txt_result" but still this result text box doesn't show me anything (it's blank). I'm probably missing something.
I just go to the properties of "txt_result", go down to AfterUpdate, go to event procedure, and the code window pops up and the cursor locates itself on the "txt_result_AfterUpdate()" function; this is where I type the code. Is this correct?

Thank you again.


CraigDolphin said:
try..
if Me.combobox = "A" then
Me.txt_result = Me.txtA * 2
...


and you might consider a 'select case' statement rather than 'if then'...it's a bit more elegant IMO

Select Case Me.combobox
Case "A"
Me.txt_result = Me.txtA * 2
Case "B"
'whatever you want to do if B is selected
Case "C"
'whatever you want to do if C is selected
Case Else
'whatever you want to do if anything other than A, B, or C is selected
End Select
 
You can't chnage the value of a control in the control's own AfterUpdate event! Put it in the control's BeforeUpdate event.
 

Users who are viewing this thread

Back
Top Bottom