i have a command button on my form that i do not want to be enabled until 1 of 10 or so passwords are typed into a text box on the same form. i wish that i had more insight on this then the zero i have, but i am pretty lost on this one. is anyone able to assist?
Well, assuming your passwords are in a table, you could load them up as an array when you open the form and then you would need to use the text box's ON CHANGE event and you would do something like this:
In the GENERAL DECLARATIONS SECTION of the form
Code:
Private varArray(1 To 10) As String
In the form's Load Event assign an array with the values
Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim i As Integer
Set db = Currentdb
Set rst = db.OpenRecordset("YourTableNameHere")
i = 1
Do Until rst.EOF
varArray(i) = rst("PasswordFieldNameHere").Value
i = i + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
And then in your ON CHANGE event of the text box you could use:
Code:
Dim i As Integer
For i = 1 To UBound(varArray)
Me.YourButtonNameHere.Enabled = (Me.YourTextBoxNameHere.Text = varArray(i))
Next
Well, assuming your passwords are in a table, you could load them up as an array when you open the form and then you would need to use the text box's ON CHANGE event and you would do something like this:
In the GENERAL DECLARATIONS SECTION of the form
Code:
Private varArray(1 To 10) As String
In the form's Load Event assign an array with the values
Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim i As Integer
Set db = Currentdb
Set rst = db.OpenRecordset("YourTableNameHere")
i = 1
Do Until rst.EOF
varArray(i) = rst("PasswordFieldNameHere").Value
i = i + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
And then in your ON CHANGE event of the text box you could use:
Code:
Dim i As Integer
For i = 1 To UBound(varArray)
Me.YourButtonNameHere.Enabled = (Me.YourTextBoxNameHere.Text = varArray(i))
Next
that code works great when i type the incorrect password in the text box. but yet the button remains enabled when i do not select the text box at all and on the load of the form itself.
do you know of any coding that does the same thing except i preload the passwords into the VBA coding? this works great for 1 of my passwords, but the reast are not triggering the command button to enable.
do you know of any coding that does the same thing except i preload the passwords into the VBA coding? this works great for 1 of my passwords, but the reast are not triggering the command button to enable.
Private varArray(1 To 9) As String
Private Sub Form_Load()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim i As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("Employees")
i = 1
Do Until rst.EOF
varArray(i) = rst("Password").Value
i = i + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Me.Command.Enabled = False
End Sub
Private Sub txtPassword_Change()
Dim i As Integer
For i = 1 To UBound(varArray)
Me.Command.Enabled = (Me.txtPassword.Text = varArray(i))
Next
End Sub
Remember, you will have to close and open the form before attempting it. The private variable is destroyed if you go into design view.
You might put a breakpoint into the on change event to step through and see what is happening as you do each keystroke, especially looking at the last one where you complete a password. My tests all worked.
Well, it would appear that you have used an Access Reserved Word for the field name ("Password") so that might have something to do with it. Other than that, you might put a breakpoint on the code that builds the array and step through it and see as each record changes what the field value shows.