syntax for using combo box to disable field (1 Viewer)

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
what would the syntax be for if the choice "Hamilton" was selected in a combo box... and have it disable the "Area" field? I got it to disable the field but it disables all "Area"in all records.

Private Sub LocationId_BeforeUpdate(Cancel As Integer)

If LocationId.Value = "Hamilton" Then
Me!AreaLocation.Enabled = False
End If

End Sub

I also tried

Private Sub LocationId_BeforeUpdate(Cancel As Integer)

If LocationId.Value = "Hamilton" Then
Me.AreaLocation.Enabled = False
End If

End Sub


Thanks
 

Jack Cowley

Registered User.
Local time
Today, 18:27
Joined
Aug 7, 2000
Messages
2,639
If the combo box is bound then you will need to put code in the On Current event to look at the value in the combo box and then enable or disable the field depening on the value in the combo box.

hth,
Jack
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
could you show me what you mean?
 

ColinEssex

Old registered user
Local time
Today, 18:27
Joined
Feb 22, 2002
Messages
9,116
Jack is saying that you should put the code in the OnCurrent property of the form to look at the value in the ComboBox every time you go from record to record.

But I'm a bit confused as to why you have this code in the BeforeUpdate of the comboBox - why not have it AfterUpdate? and why would it say "Hamilton" when you go to a different record? Isn't it blank, awaiting a selection?



Col
:cool:
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
yes but I dont want them to be able to enter eny thing. Only certain branches are broken bown by location...like call center, Teller, Computer Room etc. I couldnt get the current to work though
 

ColinEssex

Old registered user
Local time
Today, 18:27
Joined
Feb 22, 2002
Messages
9,116
If you don't want the user to enter anything in the ComboBox why have it there?

Col
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
no...I want to pick a branch from the combo box and if they select "Hamilton"..I want to disable the "Location text box on that particular entry because there cant be data for them. I might not have designed it the best, but do you know how I could do the combo box thing?

Thank!
 

ColinEssex

Old registered user
Local time
Today, 18:27
Joined
Feb 22, 2002
Messages
9,116
Ok - so like I said earlier - why not use the code AfterUpdate of the combo?

Col
:cool:
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
I get the error that says:

event procedure does not match description of event \having the same name

Thats why I didnt use it before
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
should I be using .value for a combobox?
 

ColinEssex

Old registered user
Local time
Today, 18:27
Joined
Feb 22, 2002
Messages
9,116
So what are you actually typing in the AfterUpdate event of the ComboBox?

Col
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
Private Sub LocationId_AfterUpdate()

If LocationId.Value = "Hamilton" Then
Me.AreaLocation.Enabled = False
End If

End Sub
 

ColinEssex

Old registered user
Local time
Today, 18:27
Joined
Feb 22, 2002
Messages
9,116
Sounds like things may have got a bit confused somewhere along the line.

To save alot of sodding about - I would make sure that the code is deleted from all events and re-do a new comboBox again and then put the code in the AfterUpdate and see what happens.

Don't forget to enable the field again once its been disabled, you can do that OnCurrent of the form.

Col
 

Jack Cowley

Registered User.
Local time
Today, 18:27
Joined
Aug 7, 2000
Messages
2,639
Are you using a continuous form? A single form? If you have a continuous form then what you do to one you do to all so setting the Enable property to No for one 'record' will do it for all.

This code should work for a SINGLE form if your combo box is named LocationID:

If Me.LocationId = "Hamilton" Then
Me.AreaLocation.Enabled = False
End If

I am outta here for a few hours so maybe Col can give you further assistance if you have a problem. I would suggest that you describe in detail exactly what you are doing and maybe Col can solve the problem...

Good luck and thanks Col...

Jack
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
with this code I got it to disable all of them, but not jus tthat particular record

Private Sub LocationId_AfterUpdate()


If Me.LocationId.Text = "Hamilton" Then
Me.AreaLocation.Enabled = False
End If

End Sub



I am viewing in single form view
 
R

Rich

Guest
Put the code in the OnCurrent event of the form
in the After Update of your combo put Form_Current
ie.
Private Sub Form_Current()
YouCode
End Sub


Private Sub LocationId_AfterUpdate()
Form_Current
End Sub
 
Last edited:

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
do you mean like this...it is still not working
it is telling me it need to have the focus


Private Sub LocationId_AfterUpdate()
Private Sub Form_Current()
If Me.LocationId.Text = "Hamilton" Then
Me.AreaLocation.Enabled = False
End If
End Sub
End Sub
 

Jack Cowley

Registered User.
Local time
Today, 18:27
Joined
Aug 7, 2000
Messages
2,639
Try this. If this does not work then I haven't a clue as to what is going on with your form....


Private Sub Form_Current()
If Me.LocationId.Text = "Hamilton" Then
Me.AreaLocation.Enabled = False
Else
Me.AreaLocation.Enabled = True
End If
End Sub


Private Sub LocationId_AfterUpdate()
If Me.LocationId.Text = "Hamilton" Then
Me.AreaLocation.Enabled = False
End If

Jack
 

chewy

SuperNintendo Chalmers
Local time
Today, 18:27
Joined
Mar 8, 2002
Messages
581
same problem... this is what I get.

* Move the focus to the control before you reference the property. In Visual Basic code, use the SetFocus method. In a macro, use the GoToControl action.
* Reference or set the property from a macro or event procedure that runs when the GotFocus event for the control occurs.@@2@606215@1


Im stumped!
 

Users who are viewing this thread

Top Bottom