 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 30th, 2007, 08:17 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Disable fields in a subform
I have a form with a check box called Active_Record. I have VBA code on the form that updates the enabled property for every other object on the form based on whether or not the Active_Record check box is checked.
I didn't like the way read-only fields didn't dim out when they were disabled, so I added code to set the locked property to false as the enabled property was set to false. This allowed all the fields, even the read-only ones, to be dimmed out when the record is deactivated.
This works great... with one exception. I don't know how to update the Enabled and Locked properties for the fields on my sub-forms. Can anyone suggest the code to do this?
|
|

January 30th, 2007, 08:55 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If I understand your issue correctly, you can do the following;
'Do a count of the number of (primry key) in your table that need to be updated. In this example, my primary key is SurveyID.
NumRecs = DCount("SurveyID", "READ_qryGrp1Mailing")
'Based on the number of records in the Addsamp
If NumRecs = 0 Then
MsgBox ("There are ZERO record(s) to update. Process will END")
End
End If
'else we Enable locked properties
'Off the top of my head, I don't know what that is...
|
|

January 31st, 2007, 12:54 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
O.K. I think I figured it out...
First, If you only want to make the field visible when you actually have something to update, use the code I initially sent...
What you are doing is generating a select query to see how many records need to be updated. If the results are zero records, the process stops if you have records to update, do the following to make the field active and then followed by your update query...
In a macro, add a SetValue action.
Set the Item action argument of the SetValue action to an expression that refers to the property you want to set:
To set a form or report property, use the syntax Forms!formname.propertyname or Reports!reportname.propertyname. For example, the following expression refers to the Visible property of the Customers form:
Forms!Customers.Visible
To set a property of a control on a form or report, use the syntax Forms!formname!controlname.propertyname or Reports!reportname!controlname.propertyname. For example, the following expression refers to the Visible property of the HiddenPageBreak control on the Invoices report:
Reports!Invoices!HiddenPageBreak.Visible
Reports!Invoices!HiddenPageBreak.Visible
|
|

January 31st, 2007, 02:06 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for taking the time to respond. Sorry to have been confusing, but I'm afraid I didn't communicate what I was looking for very well.
Here's a code snippet to illustrate what I'm trying to do...
if me.check_box_1.value then
me.field1.enabled = true
me.field2.enabled = true
me.field3.enabled = true
me.field3.locked = true
me.subform1.enabled = true
else
me.field1.enabled = false
me.field2.enabled = false
me.field3.enabled = false
me.field3.locked = false
me.subform1.enabled = false
endif
The third field is locked so users can't update. However, because a field that is locked does not dim out when enabled is set to false, I unlock it and disable it at the same time, and vice-versa.
This works perfectly for me, with the exception that the fields on subform1 don't dim out to show they're disabled. They are disabled and can't get the focus, but they're not dimmed out.
I thought about using conditional formatting on them, but because some of the fields are locked, I need to be able to turn lock and enabled both off.
Subform1 is a ContinuousView form, showing many records. How do I address a specific field on a specific record?
|
|

January 31st, 2007, 09:43 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I found a solution, but I'm sure there must be a programatic way to have done it. I created a copy of my subform and called it Subform1_Disabled. It's an exact duplicate, with the exception that all fields are disabled.
The new code for the Check_Box_1 on click is...
Dim strCurrentBookmark as String
if me.check_box_1.value then
me.field1.enabled = true
me.field2.enabled = true
me.field3.enabled = true
me.field3.locked = true
strCurrentBookmark = me.subform1.recordset.bookmark
me.subform1.sourceobject = "subform1"
me.subform1.recordset.bookmark = strCurrentBookmark
me.subform1.enabled = true
else
me.field1.enabled = false
me.field2.enabled = false
me.field3.enabled = false
me.field3.locked = false
strCurrentBookmark = me.subform1.recordset.bookmark
me.subform1.sourceobject = "subform1_disabled"
me.subform1.recordset.bookmark = strCurrentBookmark
me.subform1.enabled = false
endif
|
|
 |