PW to enable controls in sub-form (1 Viewer)

falcondeer

Registered User.
Local time
Yesterday, 19:34
Joined
May 12, 2013
Messages
101
Hi

I have a subform in a main form in my split DB. I added three more fields in Backend table (Provider, Date, Store). then I added controls for them in the Frontend subform.

Now, I disabled these three controls in the subform then I want the user to enable them with a PW when click on a command button.
The code for the command button I used is this:

Private Sub Command215_Click()
Dim strPassword As String
strPassword = InputBox("Please enter the password: ")

If strPassword = "123" Then
Me.tblPrescribedItems_Subform3!PR_Provider.Enabled = True - It stops here -
Me.tblPrescribedItems_Subform3!PR_ProvidingDate.Enabled = True
Me.tblPrescribedItems_Subform3!PR_ProvidingStore.Enabled = True
Else
Call MsgBox("The password you entered was incorrect")
End If
End Sub

Now I get the run-error 843 when the user enters the PW

I don't know why?

Appreciate your help.
 

Attachments

  • John-1.png
    John-1.png
    102.7 KB · Views: 126
  • John-3.png
    John-3.png
    6.6 KB · Views: 209

Gasman

Enthusiastic Amateur
Local time
Today, 03:34
Joined
Sep 21, 2011
Messages
14,221
Probably need Form on all lines?
Code:
Me.tblPrescribedItems_Subform3!Form.PR_Provider.Enabled = True
 

falcondeer

Registered User.
Local time
Yesterday, 19:34
Joined
May 12, 2013
Messages
101
Probably need Form on all lines?
Code:
Me.tblPrescribedItems_Subform3!Form.PR_Provider.Enabled = True
Same error, sorry.
 

bastanu

AWF VIP
Local time
Yesterday, 19:34
Joined
Apr 13, 2010
Messages
1,402
An alternative way to reference controls:
Me.tblPrescribedItems_Subform3.Form.Controls("PR_Provider").Enabled=True
Cheers,
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:34
Joined
Feb 19, 2002
Messages
43,213
Should be:

Me.PR_Provider.Enabled = True

Also,
ALWAYS give your controls meaningful names. Command215 is meaningless. All it tells anyone is that you've modified this form way too many times to get all the way up to 215 in the numbering scheme.
 

falcondeer

Registered User.
Local time
Yesterday, 19:34
Joined
May 12, 2013
Messages
101
Thanks for all of you, but nothing is working.

One thing I have noticed: the code line is working fine when I apply it to any other controls created with the subform in the beginning, those three fields and controls are added yesterday in the split DB and to the subform and the same code is not working.

Does this has any clue?

Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:34
Joined
Sep 21, 2011
Messages
14,221
It all depends on where you are executing the code from and where the controls are.?
You have to compare like with like. Too many times people say I have the same code working elsewhere, when it is not the same code at all:(

Use the intellisense to get the correct syntax.?
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:34
Joined
May 7, 2009
Messages
19,228
are you sure you are using the correct subform/control name?

[Forms]![YourMainFormName]![tblPrescribedItems_Subform3].[Form]![PR_Provider].Enabled = True
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 22:34
Joined
Feb 19, 2002
Messages
43,213
If you want to enable/disable controls for a SPECIFIC record, the toggle code MUST be in a subform event. If you have the event code in a button on the main form but you have lock code in the current event of the subform, the current event will override the button code because it will run after the button code.
 

falcondeer

Registered User.
Local time
Yesterday, 19:34
Joined
May 12, 2013
Messages
101
you post your db, so we don't only have clue but also some leads.
I don't mind but the front end will not work I believe and my DB has already patient names and their medical record numbers.
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:34
Joined
Sep 21, 2011
Messages
14,221
I don't mind but the front end will not work I believe and my DB has already patient names and their medical record numbers.
See one of my links for anoymizing the data.?
Just create a new DB, copy in just what is needed. You can make the relevant tables local in the new db.? Add a few records and amend with that link or manually if only a few records
Then compact, zip and upload.
 

Users who are viewing this thread

Top Bottom