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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text box based on Combo Box in Standalone Form

Status
Not open for further replies.

MSealy

MIS
Sep 2, 2001
56
GB
I have a form called frmCCPYT, a combo box called comboCard, and 3 text boxes called txtAMT, txtCHG and txtTOT.

Basically, I have a standalone form which needs to apply a charge to txtAMT, depending on the value of comboCard.
i.e. MasterCard is the first value in the box and is presumably ItemData(0) which needs to add a charge of 1.45% displayed in txtCHG.
ItemData(2) (Maestro) needs to add 2.5%, and
ItemData(3) (Switch) applies no charge.
txtTOT then adds txtAMT & txtCHG.

I've tried various combinations of If, Then Else, and End If, but can't seem to get it working.

Any one got any ideas?
 
combobox are tricky.
To retrieve what was choosed by the user do this on the change event of the combo itself:

Select case combo.value

case is 0
txtCHG.text = VAL(txtAMT.text)* 1.45)/100
case is 1 ' maestro
txtCHG.text = VAL(txtAMT.text)* 2.45)/100
case is 2 'switch
txtCHG.text = "0.00"

end select

txtTOT.Text = VAL(txtAMT.text) + VAL(txtCHG.text)


HTH
Alcar
 
Thanks for the help.
Unfortunately Access didn't like the case without =, or the combo.value. I managed to sort

it, but the line after 'End Select' goes wrong after selecting an item in the combo box.
It returns the error "Runtime error 2185 - Can't reference a property or method for control

unless control has the focus".

Could there be a conflict with control sources in the textboxes?
As it's a standalone form, txtAMT has no control source, neither does txtCHG.
However, txtTOT has "=[Forms]![frmCCPYT]![txtAMT]+[Forms]![frmCCPYT]![txtCHG]+[txtAMT]" as

its control source.

I've tried deleting this control source, changing the format of your line, and deleting the

line, but none of these work.

Here's the updated code.

Private Sub comboCard_Change()
Select Case comboCard.Value
Case Is = 0 'MasterCard
txtCHG.Text = Val(txtAMT.Text) * 1.45 / 100
Case Is = 1 'VISA
txtCHG.Text = Val(txtAMT.Text) * 1.45 / 100
Case Is = 2 'Maestro
txtCHG.Text = Val(txtAMT.Text) * 2.50 / 100
Case Is = 3 'VISA Debit
txtCHG.Text = "0.00"
Case Is = 4 'Switch
txtCHG.Text = "0.00"
End Select
txtTOT.Text = Val(txtAMT.Text) + Val(txtCHG.Text)
End Sub

As with the run time error - surely txtCHG can't have the focus while I'm changing the combo

box, can it??

Also, would it make it easier if I used a one-record locked table (with some sort of clear

facility) as the control source of the form instead of keeping it standalone?
 
MSealy,

No need to set txtTot in the codes. Have the default value of txtTOT set to add the two numbers together and all should be fine.

Craig
 
Try to give the texttot the focus like this after the end select

txtTOT.SetFocus
txtTOT.Text = Val(txtAMT.Text) + Val(txtCHG.Text)
End Sub

HTH
Alcar
 
I still get run time error 2185 - (the focus problem)

These are my current settings

txtAMT
Unbound

txtCHG
=[Forms]![frmCCPYT]![txtCHG]+[txtAMT]-[txtAMT]

txtTOT
=[Forms]![frmCCPYT]![txtAMT]+[txtCHG]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top