473,411 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

VBA - Changing subform field's property from mainform button

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.

Code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEdit_Click()
  2.  
  3. Dim strPasswd
  4.  
  5.     strPasswd = InputBox("Please insert the password to edit records", "Access restricted")
  6.  
  7.     If strPasswd = "" Or strPasswd = Empty Then
  8.         MsgBox "Cancelled.", vbInformation, "Insert password."
  9.         Exit Sub
  10.     End If
  11.  
  12.     If strPasswd = "password1" Then
  13.  
  14.     'unlocks fields in main forms
  15.         Me!cmdNewRecord.Enabled = True
  16.         Me!txtSubject.Locked = False
  17.  
  18.     'unlocks fields in subform 1
  19.         Me!subAquisitions.Form!txtPrice.Locked = False
  20.  
  21.     'unlocks fields in subform 2
  22.         Me!subResponsible.Form!txtName.Locked = False
  23.  
  24.  
  25.     Else
  26.         MsgBox "Sorry, wrong password.", _
  27.                vbOKOnly, "Try again"
  28.         Exit Sub
  29.     End If
  30.  
  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
5 4077
mshmyob
904 Expert 512MB
Proper syntax would be:

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

cheers,
Mar 1 '10 #2
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
mshmyob
904 Expert 512MB
Interesting... could you attach a stripped down version of your database so I can check the form?

cheers,
Mar 1 '10 #4
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
mshmyob
904 Expert 512MB
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.

cheers,
Mar 2 '10 #6

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

Similar topics

15
by: Rey | last post by:
Howdy all. Appreciate your help with several problems I'm having: I'm trying to determine if the Visit subform (subformVisits) has a new record or been changed, i.e. dirty. The form that...
0
by: P Mitchell | last post by:
Hello I would like someone to be able to help with the updating of data in a lookup list in a subform. In short, is their a VB instruction that is the equivalent of performing the action of...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
1
by: Johnny Meredith | last post by:
I have an unbound main form (one side) with a subform (many side). The main form has a textbox control on it whose visible property is set to false. It's controlsource property is a reference to...
1
by: planetthoughtful | last post by:
Hi All, I have a mainform with a subform in which I show some task summary data. On the mainform I have a number of unbound controls that reflect values relevant to each task in the subform....
3
by: panwala_bhavesh | last post by:
I have a subform in continuous form style that I use to populate 3 fields (textboxes) on my main form with a double-click of the key-field textbox of the sub: Private Sub...
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
18
by: Robert Jacobs | last post by:
Please advise... I currently have a Mainform (Customers) and a Subform (Service Requests) with a one to many relationship (one customer, many service requests) with a CustomerID that is unique...
5
by: samdev | last post by:
I have created two combo boxes in a subform.... For example 1. Combo Box State 2. Combo Box City 3. When a state from the Combo Box State is selected, the City combo box updates to reflect...
24
by: bkberg05 | last post by:
Hi - I have a form called mainForm that has a subform called subForm. The subform has a numeric field called subCost. There are many subForm records for every mainForm record. On the main form,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.