Using a combo box selection to lock and unlock a text box in a form

Nightshade

New member
Local time
Today, 06:49
Joined
Nov 26, 2008
Messages
4
I am creating a database for a church. In my event form I have a combo box that will allow the user to select the various events the church is involved in. One of those events types is called Pastoral Calling and with that specific event the pastor needs to keep track of his mileage for reimbursement by the church and tax purposes.

There is a text box in the form for the pastor to enter his mileage for the Pastoral Calling. I want to lock this text box so it will not be possible to enter any data in this textbox unless the Pastoral Calling is selected in the event list combo box. Here is the code.

Code:
Private Sub cboEventType_AfterUpdate()
'On after selection update of the event type in Event form
'Check if Event Type: Pastoral Call is selected
'Then lock or unlock the Mileage textbox
    If Me.cboEventType = "Pastoral Call" Then
        Me.txtMileage.Locked = False
    Else
        Me.txtMileage.Locked = True
    End If
End Sub
The same code also exists for the On Current event. The problem is when I selected pastoral calling in the combo box and tried to enter numbers in the mileage text box nothing happens and it behaves as if it is a locked text box. I know I am missing something but I can't figure out what. Any ideas?

P.S. Oh and I tried the on click event as well, same results.
 
Try changing Me.txtMileage.Locked to
Me.txtMileage.enabled

Alan
 
Is that text what's in the bound column, or is it perhaps an ID? What's the rowsource of the combo?
 
The rowsourse of the combo box is a separate table called EVENT_LIST that has the listing of all the events. The key field aka the Event Type ID number is hidden in the combo box selection. The Pastoral Calling event ID number is 9.
 
Have you tried testing for 9 instead of the text?
 
When you refer to the combo, you get what's contained in the bound column, which in this case is the ID. I'm guessing you could have used

Me.cboEventType.Column(1)

and used the text.
 
Something tells me that using the event name ID would be simpler. Simple code is good code I always say.

Alansidman, I used your suggestion on enabling and disabling fields rather than locking them. It looks a lot better.

This is a great forum. This is my first attempt at using VBA in a access database. The VBA is quite impressive.

Thanks for all your help and suggestions.
 

Users who are viewing this thread

Back
Top Bottom