By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

VBA - Changing subform field's property from mainform button

P: 5
Evening guys.

Here something that's been driving me nuts for the past couple of hours.

I have a mainform and in it, two subforms. Normally I'd like the fields to be read-only, but if a user has the right password he'd be able to click on a button on the mainform and turn the "locked" property on all the fields to FALSE.


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEdit_Click()
  3. Dim strPasswd
  5.     strPasswd = InputBox("Please insert the password to edit records", "Access restricted")
  7.     If strPasswd = "" Or strPasswd = Empty Then
  8.         MsgBox "Cancelled.", vbInformation, "Insert password."
  9.         Exit Sub
  10.     End If
  12.     If strPasswd = "password1" Then
  14.     'unlocks fields in main forms
  15.         Me!cmdNewRecord.Enabled = True
  16.         Me!txtSubject.Locked = False
  18.     'unlocks fields in subform 1
  19.         Me!subAquisitions.Form!txtPrice.Locked = False
  21.     'unlocks fields in subform 2
  22.         Me!subResponsible.Form!txtName.Locked = False
  25.     Else
  26.         MsgBox "Sorry, wrong password.", _
  27.                vbOKOnly, "Try again"
  28.         Exit Sub
  29.     End If
  31. End Sub
Pretty straightforward..but no good so far...:(

The button unlocks the MAIN form's fields okay, but then I get this: "Run-time error '2465': Mainform can't find the field 'txtPrice' referred to in your expression."

An ideas? Thanks for the help!
Mar 1 '10 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 903
Proper syntax would be:

Expand|Select|Wrap|Line Numbers
  1. Me!MainformName!subAquisitions.Form.txtPrice.Locked = False 
I usually just allow or diasallow edits, deletions, etc. for the entire subform rather than the individual controls but either way will work.

Mar 1 '10 #2

P: 5
Thanks mshmyob, I tried it though I seem to get a slightly different error:

"Run-time error '2465': Mainform can't find the field 'frmProductData' referred to in your expression."

Of course "frmProductData" is the name of the form...and it still can't find it! How weird is that?

Oh, I also know that the subforms are each in their own controls, I checked their names and they match the ones in the first example, and it still can't find them :(
Mar 1 '10 #3

Expert 100+
P: 903
Interesting... could you attach a stripped down version of your database so I can check the form?

Mar 1 '10 #4

P: 5
Alright, I'll try to as soon as possible...I think I'll have to start it from scratch as there's too much company information, even in the descriptions and code. Thanks for the help, though!
Mar 2 '10 #5

Expert 100+
P: 903
Just copy the form and paste it into a new database ( this will have a database with only the form and no data). I just want to see your syntax.

Mar 2 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.