PDA

View Full Version : MS Access VBA Combo Box Help



thecronman
08-06-2012, 05:27 AM
Hello-

I am having a issue. I created a form. For one of the combo boxes on this form it gives you a drop down list of choices. In order to select anything in this combo box, you will be prompted for a password. If the password is
incorrect, I would like the combo box to unselect itself or go to a default choice. I cannot get this code to operate properly. The row source type is table/query. I have tried.

Combo5 = Null
Combo5 = “”
Me.Combo5 = Me.Combo5.DefaultValue

And several others. How important are the attributes associated to the combo box? Such as Row Source Type, Row Source ext…

Thanks, Mike

awelane
08-07-2012, 06:58 AM
My suggestion is that you not try to do everything with the combobox.
Instead, use a textbox in front of the combobox as a gatekeeper.
Have the user enter a password into a textbox, and if correct, show the combobox.
Otherwise, keep the combobox hidden.

Here's how that would work:
(I will use cboRestricted as the example combobox name and txtGatekeeper as the example textbox name).

Create a textbox, with the same dimensions as your combobox. In the textbox's label, put a title like: "Enter password for access to restricted combobox"
Set the combobox's VISIBLE property to FALSE.
Put the textbox right on top of the combobox.

Then, in the txtGatekeeper_AfterUpdate routine, put code like this:

Private Sub txtGatekeeper_AfterUpdate()
If Me.txtGatekeeper = "CorrectPassword" Then
Me.txtGatekeeper.Visible = False
Me.cboRestricted.Visible = True
Else
Msgbox "Password entered is incorrect. Please enter correct password."
Me.txtGatekeeper = ""
Me.txtGatekeeper.SetFocus
End If
End Sub