Hello Forum,
I have been searching the net (and finding answers that give me error messages) and am about to say goodbye to any sanity I have left…
Context : I have a main form (MainForm) based on a query, with:
- Unbound controls at the top that allow users to filter data – UNLOCKED by default
- Tab control (5 tabs)
- Textboxes, comboboxes, checkboxes scattered in the MainForm and the tabs - all of those are set to LOCKED by default.
- Subforms, whose controls are set to LOCKED by default, scattered in the tabs
I have a button on said MainForm that prompts a Password window and when you have entered the right password and clicked ok, you should be able to change any data you need.
Here is the code I have for the Ok button:
Code:
Private Sub btnOK_Click()
If IsNull(Me.txtPassword) Then
MsgBox "Enter password", vbInformation
Me.txtPassword.SetFocus
Exit Sub
End If
If Me.txtPassword = "Secret" Then
Forms!MainForm.FiltreBail.SetFocus
DoCmd.Close acForm, "Fm_Password"
With Forms![MainForm]
Dim ctl As Control
For Each ctl In Forms![MainForm].Controls
If TypeOf ctl Is TextBox Or TypeOf ctl Is CheckBox Or TypeOf ctl Is ComboBox Then
ctl.Locked = False
ElseIf TypeOf ctl Is CommandButton Then
ctl.Visible = True
End If
Next
End With
blnPasswordOK = True
Else
MsgBox "Incorrect password.", vbExclamation
Me.txtPassword.SetFocus
End If
End Sub
I am facing two problems:
- Controls on my last tab (5) don’t unlock and I am unable to modify anything in this tab (4 combos and 8 textboxes).
- I have been trying for two day to add code to unlock controls in my subforms with pieces of code I pick here and there but it is a fail each time: either I don’t get any error message but nothing happens, either I get the 2465 or 2467 error message.
Here are a few of the examples I adapted to my case:
Code:
Me.[Subform1].Form.[Controlname1].Locked = False
…
Me.Controls("Subform1").Form.Controls("Controlname1").Locked = False
…
With Forms![MainForm]!Subform1
.Form! Controlname1.Locked = False
.Form!Controlname2.Locked = False
.Form!Controlname2.Locked = False
End With
May I add that I know enough to adapt any code to my projects but not enough to get myself out of that kind of trouble
Thank you very much in advance.
S.