Combo enabling text box - code error?

fraser_lindsay

Access wannabe
Local time
Today, 21:26
Joined
Sep 7, 2005
Messages
218
I am trying to get a text box to be enabled or disabled according to one of five values in a combo box.

Here's my code in the after update event of the combo box:

Code:
Private Sub cboJD_lift_freq_AfterUpdate()

If Me.cboJD_lift_freq.Value = "N/A" Or Me.cboJD_lift_freq.Value = "N" Then
Me.txtJD_lift_max.enabled = False
Else: Me.txtJD_lift_max.enabled = True
End If

If Me.cboJD_lift_freq.Value = "O" Or Me.cboJD_lift_freq.Value = "F" Or Me.cboJD_lift_freq.Value = "C" Then
Me.txtJD_lift_max.enabled = True
Else: Me.txtJD_lift_max.enabled = False
End If

End Sub


It works when I load the form and when I change to "N/A" or "N" it disables the text box but when I try and change back to "O", "F" or "C" it remains disabled.

What have I done wrong?

Also does this need to go in the combo box 'After Update' AND the form's On Current event?

Thanks
 
Try the same but drop the .Value syntax from your SQL
 
Hi,

It does the same. It's enabled on form load for "O", but if I change it to any oother option it disables.

It thinks about it and changes very briefly after a change but then just disables it and won't re-enable on any of the options.
 
try this

Code:
Select Case Me.cboJD_lift_freq
    Case "N/A", "N"
      Me.txtJD_lift_max.Enabled = False
    Case "O", "F", "C"
      Me.txtJD_lift_max.Enabled = True
End Select
 
Ok, this time the box remained enabled for all options.

Sorry to drag this out, I hoped it would be fairly simple.
 
Still haven't got this to work.

Can somebodey confirm exactky which event I shoudl be using for this? I am trying AfterUpdate, but have also tried On Change and On Click. Without any sucess so far.

It seems that having two options in the combo box is simple i.e. it's either one or the other, and the text box is either on or off.

I just can't seem to get it to do it with multiple options in the text box.

Does anyone have any other suggestions?
 
It might be easier to see why it isn't working if you could post the relevent part of your DB
 
It is definitely the AfterUpdate event you want, here is an example database demonstrating the correct code, it's the same as what DCrake said. But maybe this example will help you figure it out.

If this code doesn't work for you, there is something else messing it up, and you would have to post the database as Rabbie said.
 

Attachments

Gents, I've tried exactly as suggested but can't seem to get it to work.

Here's an abbreviated chunk of the database.

The form is 'frmJSA'

The tab is 'Job Demands'

I'm trying to get this to work on four fields which require some form of weight value. The example I gave above was 'lifting frequency' combo and the text box is the 'maximum lifting weight'.

I'm stumped.
 

Attachments

I found your problem:

Code:
Private Sub cboJD_lift_freq_AfterUpdate()
Select Case Me.cboJD_lift_freq
    
    Case 1, 2
      Me.txtJD_lift_max.enabled = False
    Case 3, 4, 5
      Me.txtJD_lift_max.enabled = True
    End Select
End Sub

Your combobox's value after update is colum(0), witch is your ID field.

JR:)
 
Fantastic! :)

You have no idea how much this has been bugging me. Thank you very much, I'll update all four now.

Fraser
 

Users who are viewing this thread

Back
Top Bottom