Locking Comboboxes using VBA

leedub

Registered User.
Local time
Today, 00:21
Joined
Jul 9, 2013
Messages
18
Hello Im working in MS Access 2007.

I have 3 combo boxes on a form. My goal is simple I would like the 2nd and 3rd comboboxes to be locked unless the user has already chosen selected an item from the 1rst combo box.

The code im trying to get working now is in a On_Current event so that when the first combo box has nothing selected, combo box 2 and 3 are locked.

This is my code where
combo box 1 = areabox2
combo box 2 = devbox2
combo box 3 = entitybox2

Private Sub Form_Current()

If Me!areabox2 = Null Then
Me!devbox2.Locked = True
Me!entitybox2.Locked = True

Else
Me!devbox2.Locked = False
Me!entitybox2.Locked = False
End If

End Sub

The issue is that the entitybox2 and devbox2 do not lock!

Any help is apreciated!
 
You can't test for Null that way. You can use

If IsNull(Me!areabox2) Then

or

If Len(Me!areabox2 & vbNullString) = 0 Then
 
Alright i have changed that now but it Still allows me to select from combobox 2 and 3 before i have selected from combobox 1.

This is what my code looks like now

Private Sub Form_Current()

If IsNull(Me!areabox2) Then
Me!devbox2.Locked = True
Me!entitybox2.Locked = True

Else
Me!devbox2.Locked = False
Me!entitybox2.Locked = False
End If

End Sub
 
What I would do is lock devbox2 and entitybox2 either in the form_load or using the properties sheet.

Then in the areabox2_AfterUpdate event I would place this code:
Code:
Private Sub areabox2_AfterUpdate()

If IsNull(Me!areabox2) Then
    msgbox "Areabox cannot be blank"
    Me.areabox2.SetFocus
   Exit Sub
 Else
    Me!devbox2.Locked = False
    Me!entitybox2.Locked = False
 End If
 
End Sub
 

Users who are viewing this thread

Back
Top Bottom